Fix mypy errors on Python 3.10 (#2441)

termios.tcgetwinsize and termios.tcsetwinsize were added in Python 3.11, which caused undefined-attr typing errors when linting on python 3.10.

mypy doesn't support the Python version indirection of a global constant, so move the condition into the if statement.
pull/2439/head^2
peace-maker 1 year ago committed by GitHub
parent c6c5f1dec1
commit 6e9cdac13a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -26,12 +26,6 @@ if os.name == "posix":
TERM_CONTROL_AVAILABLE = True
SELECT_AVAILABLE = True
PTY_AVAILABLE = True
# We could support querying the terminal size in older versions of Python,
# too, but, for now, this should be good enough.
#
# TODO: Properly support terminal size queries in Python 3.10 and older.
PTY_TERMSIZE_AVAILABLE = sys.version_info.minor >= 11
else:
# We sleep for a little bit when we don't have select.
import time
@ -389,8 +383,12 @@ class IODriverPseudoTerminal(IODriver):
# Put the manager in nonblocking mode.
os.set_blocking(self.manager, False)
# We could support querying the terminal size in older versions of Python,
# too, but, for now, this should be good enough.
#
# TODO: Properly support terminal size queries in Python 3.10 and older.
# Handle terminal resizes.
if PTY_TERMSIZE_AVAILABLE:
if sys.version_info >= (3, 11):
# The way we currently handle terminal resizing absolutely does not
# support multipleinstances of IODriverPseudoTerminal, but we
# shouldn't have more than one object live at a time anyway for the
@ -399,7 +397,7 @@ class IODriverPseudoTerminal(IODriver):
terminal = open("/dev/tty", "rb")
def handle_sigwinch(_sig, _frame):
# Tell vermin to ignore these. PTY_TERMSIZE_AVAILABLE is
# Tell vermin to ignore these. This block is
# gated behind Python 3.11.
size = termios.tcgetwinsize(terminal.fileno()) # novm
termios.tcsetwinsize(self.manager, size) # novm

Loading…
Cancel
Save