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

unused-imports uses hardcoded list for typing.TYPE_CHECKING #3846

Closed
dcbaker opened this issue Sep 18, 2020 · 5 comments · Fixed by #6787
Closed

unused-imports uses hardcoded list for typing.TYPE_CHECKING #3846

dcbaker opened this issue Sep 18, 2020 · 5 comments · Fixed by #6787
Assignees
Labels
Enhancement ✨ Improvement to a component False Positive 🦟 A message is emitted but nothing is wrong with the code typing
Milestone

Comments

@dcbaker
Copy link

dcbaker commented Sep 18, 2020

In meson we import the typing module as T, as a sort of compromise between using the full typing name, and polluting the local namespace.

Steps to reproduce

import typing as T
if T.TYPE_CHECKING:
    import Foo

Looking at the code it uses a hardcoded set {'typing.TYPE_CHECKING', 'TYPE_CHECKING'}, using any other value will be ignored and spurious errors will ensue.

For my use, being able to add T.TYPE_CHECKING to the pylintrc would be sufficient, but maybe this can resolved in a more generic way?

@graingert
Copy link
Contributor

graingert commented Sep 19, 2020

pylint should definitely track what typing is imported as, and really must not consider import keyboarding as typing; typing.TYPE_CHECKING a match either.

but you'll probably not need this as most of the common stuff in typing is now moved to builtins and collections.abc

Then all the uncomon stuff typing.Protocol, typing.TypeVar, typing.cast justify using the full import typing name

@graingert
Copy link
Contributor

there's also

MYPY = False
if MYPY:
    import bar

to consider

@dcbaker
Copy link
Author

dcbaker commented Sep 19, 2020

We need to support all versions of python the python foundation does. We're just getting ready to drop 3.5 support after our next release. So using the not in typing names won't happen for a lot of years for us.

@graingert
Copy link
Contributor

graingert commented Sep 19, 2020

@dcbaker you don't need python 3.9+ to use pep585 generics in builtins, mypy will support them (in forward annotations) on all Python versions

@PCManticore PCManticore added Enhancement ✨ Improvement to a component typing labels Dec 27, 2020
@PCManticore
Copy link
Contributor

Thanks for the report; I agree that we need to improve the situation here.

@jacobtylerwalls jacobtylerwalls self-assigned this Jun 1, 2022
@jacobtylerwalls jacobtylerwalls added this to the 2.15.0 milestone Jun 1, 2022
@jacobtylerwalls jacobtylerwalls modified the milestones: 2.15.0, 2.14.1 Jun 1, 2022
@jacobtylerwalls jacobtylerwalls added the False Positive 🦟 A message is emitted but nothing is wrong with the code label Jun 1, 2022
@jacobtylerwalls jacobtylerwalls modified the milestones: 2.14.1, 2.15.0 Jun 1, 2022
@jacobtylerwalls jacobtylerwalls modified the milestones: 2.15.0, 2.14.1 Jun 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ✨ Improvement to a component False Positive 🦟 A message is emitted but nothing is wrong with the code typing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants