Skip to content

added type references to pager.py, mypy produced no errors #936

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 9, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
made suggested changes, after modifing local virtualenv no longer rec…
…ieving mypy errors
  • Loading branch information
Frostmaine committed Nov 9, 2021
commit 668524a436632d932e9cd663fbaf252968d2a932
2 changes: 1 addition & 1 deletion bpython/_internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from .pager import page

# Ugly monkeypatching
pydoc.pager = page
pydoc.pager = page # type: ignore


class _Helper:
Expand Down
4 changes: 3 additions & 1 deletion bpython/pager.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@
import subprocess
import sys
import shlex
from typing import List


def get_pager_command(default: str = "less -rf") -> list[str]:
def get_pager_command(default: str = "less -rf") -> List[str]:
command = shlex.split(os.environ.get("PAGER", default))
return command

Expand All @@ -53,6 +54,7 @@ def page(data: str, use_internal: bool = False) -> None:
curses.endwin()
try:
popen = subprocess.Popen(command, stdin=subprocess.PIPE)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me this needs a

Suggested change
popen = subprocess.Popen(command, stdin=subprocess.PIPE)
assert popen.stdin is not None
popen = subprocess.Popen(command, stdin=subprocess.PIPE)

to silence mypy errors about stdin maybe being None.

assert popen.stdin is not None
data_bytes = data.encode(sys.__stdout__.encoding, "replace")
popen.stdin.write(data_bytes)
popen.stdin.close()
Expand Down