Skip to content

Fix various files so the entire trio/ directory can be type-checked#2763

Merged
jakkdl merged 9 commits intopython-trio:masterfrom
jakkdl:typing_various_files
Aug 18, 2023
Merged

Fix various files so the entire trio/ directory can be type-checked#2763
jakkdl merged 9 commits intopython-trio:masterfrom
jakkdl:typing_various_files

Conversation

@jakkdl
Copy link
Member

@jakkdl jakkdl commented Aug 17, 2023

This is a squash of #2721 to avoid having to navigate a huge and messy PR. It consists of a ton of small fixes or type: ignores to any file that raised errors when running mypy trio/, and it also transitions pyproject.toml from being a list of files to check strictly, to an ignore-list with files to disable strict checks for. This doubles as a TODO-list, and it's easy to explode wildcards, or remove a disabled check, or similar.

The test changes has caught several small typing errors introduced in various PRs that haven't been checked in CI, or when files have been forgotten to get added.

All the changes should be non-controversial, if anything is up for debate I'll just mark it with a comment and/or revert it, and add it to #2734 or directly split out to a separate PR

@codecov
Copy link

codecov bot commented Aug 17, 2023

Codecov Report

Merging #2763 (cb6214e) into master (4c38ba9) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2763      +/-   ##
==========================================
+ Coverage   98.92%   98.93%   +0.01%     
==========================================
  Files         113      113              
  Lines       16728    16752      +24     
  Branches     3026     3027       +1     
==========================================
+ Hits        16548    16574      +26     
+ Misses        124      123       -1     
+ Partials       56       55       -1     
Files Changed Coverage Δ
trio/_tools/gen_exports.py 100.00% <ø> (ø)
trio/_core/_io_common.py 100.00% <100.00%> (ø)
trio/_core/_ki.py 100.00% <100.00%> (ø)
trio/_core/_parking_lot.py 100.00% <100.00%> (ø)
trio/_core/_tests/test_io.py 100.00% <100.00%> (ø)
trio/_core/_tests/test_ki.py 97.82% <100.00%> (+0.01%) ⬆️
trio/_core/_tests/test_multierror.py 100.00% <100.00%> (ø)
trio/_core/_tests/test_run.py 100.00% <100.00%> (ø)
trio/_core/_wakeup_socketpair.py 100.00% <100.00%> (ø)
trio/_path.py 100.00% <100.00%> (ø)
... and 12 more

Copy link
Member Author

Choose a reason for hiding this comment

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

without (possibly a subset of) the changes to _fake_net:

trio/testing/_fake_net.py:107: error: Signature of "socket" incompatible with supertype "SocketFactory"  [override]
trio/testing/_fake_net.py:107: note:      Superclass:
trio/testing/_fake_net.py:107: note:          def socket(self, family: Union[AddressFamily, int, None] = ..., type: Union[SocketKind, int, None] = ..., proto: Optional[int] = ...) -> _SocketType
trio/testing/_fake_net.py:107: note:      Subclass:
trio/testing/_fake_net.py:107: note:          def socket(self, family: int, type: int, proto: int) -> FakeSocket
trio/testing/_fake_net.py:116: error: Argument 1 of "getaddrinfo" is incompatible with supertype "HostnameResolver"; supertype defines the argument type as "Union[bytes, str, None]"  [override]
trio/testing/_fake_net.py:116: note: This violates the Liskov substitution principle
trio/testing/_fake_net.py:116: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
trio/testing/_fake_net.py:116: error: Argument 2 of "getaddrinfo" is incompatible with supertype "HostnameResolver"; supertype defines the argument type as "Union[bytes, str, int, None]"  [override]
trio/testing/_fake_net.py:131: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
trio/testing/_fake_net.py:179: error: Need type annotation for "_packet_sender"  [var-annotated]
trio/testing/_fake_net.py:179: error: Need type annotation for "_packet_receiver"  [var-annotated]
Found 5 errors in 1 file (checked 129 source files)

@jakkdl jakkdl merged commit a316034 into python-trio:master Aug 18, 2023
@jakkdl jakkdl deleted the typing_various_files branch August 18, 2023 08:35
@jakkdl
Copy link
Member Author

jakkdl commented Aug 18, 2023

merging this one so any additional minor problem in other typing PRs can be caught, gonna lead to a bunch of merge conflicts in pyproject.toml either way

@A5rocks A5rocks added the typing Adding static types to trio's interface label Aug 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

typing Adding static types to trio's interface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants