Skip to content
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

Forbid imports of collections.abc aliases from typing #213

Merged
merged 4 commits into from
Apr 18, 2022

Conversation

AlexWaygood
Copy link
Collaborator

@AlexWaygood AlexWaygood commented Apr 18, 2022

A regression test for python/typeshed#7635

Refs #46 (but doesn't quite close it).


Changes made

  • Expand Y027 to cover all objects in typing that are aliases to objects in collections.abc, except for AbstractSet
  • Add new Y038 error code to forbid import AbstractSet from typing
  • Change the error message in Y023 to make it clear that imports from collections.abc are now preferred to imports from typing.
  • Refactor Y023 logic in pyi.py so as to quell flake8 from complaining that _check_import_or_attribute was getting too complex.
  • Some small refactorings of test files to make them compatible with the new checks.

@AlexWaygood
Copy link
Collaborator Author

  • Use PEP 585 syntax in collections python/typeshed#7657 for the collections hits
  • The output of typeshed_primer makes it look like there's a lot of hits in _collections_abc and builtins, but in reality, we only need one # noqa comment in each module, since all the imports are on the same line. Combined with the hit in types and the hit in array, we'll need to add 4 # noqa comments to typeshed if we merge this.

pyi.py Show resolved Hide resolved
pyi.py Outdated Show resolved Hide resolved
pyi.py Outdated Show resolved Hide resolved
@AlexWaygood
Copy link
Collaborator Author

typeshed PR to add the required # noqas:

srittau pushed a commit to python/typeshed that referenced this pull request Apr 18, 2022
AlexWaygood added a commit to python/typeshed that referenced this pull request Apr 18, 2022
JelleZijlstra pushed a commit to python/typeshed that referenced this pull request Apr 18, 2022
@JelleZijlstra JelleZijlstra reopened this Apr 18, 2022
pyi.py Outdated Show resolved Hide resolved
@AlexWaygood AlexWaygood merged commit fd2bae8 into PyCQA:master Apr 18, 2022
@AlexWaygood AlexWaygood deleted the 585 branch April 18, 2022 20:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants