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

Y047 false negative for conditionally defined aliases #383

Closed
AlexWaygood opened this issue May 14, 2023 · 0 comments · Fixed by #384
Closed

Y047 false negative for conditionally defined aliases #383

AlexWaygood opened this issue May 14, 2023 · 0 comments · Fixed by #384
Labels

Comments

@AlexWaygood
Copy link
Collaborator

AlexWaygood commented May 14, 2023

This caused me some confusion in python/typeshed#10177, where I expected Y047 to be emitted, but it wasn't.

Code like this currently doesn't cause Y047 to be emitted, but it probably should:

import sys
from typing_extensions import TypeAlias

if sys.version_info >= (3, 12):
    _Foo: TypeAlias = str
else:
    _Foo: TypeAlias = int

The reason is that this logic here is too naive:

flake8-pyi/pyi.py

Lines 1937 to 1939 in 5b17698

for alias_name, alias in self.typealias_decls.items():
if self.all_name_occurrences[alias_name] == 1:
self.error(alias, Y047.format(alias_name=alias_name))

If an alias is conditionally defined, as above, the name of the type alias ("_Foo") will appear more than once in the file (it will appear once for each conditional definition), which leads flake8-pyi to assume that the type alias has been "used" at least once in the file that it's been defined in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant