Skip to content

termios: Fix type of tcgetattr and tcsetattr attributes #4662

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 1 commit into from
Oct 13, 2020

Conversation

cebtenzzre
Copy link
Contributor

Returning a union from tcgetattr forces the caller to use isinstance or
a type: ignore comment if they modify the returned list. Return
List[Any] instead.

The cc field has ints at cc[termios.VTIME] and cc[termios.VMIN] if
lflag & termios.ICANON is zero. Change _Attr to allow this.

Fixes #4661

The goal is to avoid false positives like this:

example.py:6: error: Unsupported operand types for & ("List[bytes]" and "int")  [operator]
        new[3] = new[3] & ~termios.ECHO          # lflags
                 ^
example.py:6: note: Left operand is of type "Union[int, List[bytes]]"
example.py:7: error: Unsupported target for indexed assignment ("Union[int, List[bytes]]")  [index]
        new[6][termios.VMIN] = 0
        ^
example.py:7: error: No overload variant of "__setitem__" of "list" matches argument types "int", "int"  [call-overload]
        new[6][termios.VMIN] = 0
        ^
example.py:7: note: Possible overload variants:
example.py:7: note:     def __setitem__(self, int, bytes) -> None
example.py:7: note:     def __setitem__(self, slice, Iterable[bytes]) -> None
Found 3 errors in 1 file (checked 1 source file)

Returning a union from tcgetattr forces the caller to use isinstance or
a type: ignore comment if they modify the returned list. Return
List[Any] instead.

The cc field has ints at cc[termios.VTIME] and cc[termios.VMIN] if
lflag & termios.ICANON is zero. Change _Attr to allow this.

Fixes python#4661
Copy link
Collaborator

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

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

Thanks again!

@hauntsaninja hauntsaninja merged commit 58ee9c0 into python:master Oct 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

termios: Definition of tcgetattr causes false positives
2 participants