Imports removed incorrectly with Generic class type annotation
See original GitHub issueExample code where a used import is incorrectly removed by autoflake:
from __future__ import annotations
from .scheduled_events import ScheduledEventUser
class _AsyncIterator(AsyncIterator[T]):
...
class ScheduledEventUserIterator(_AsyncIterator["ScheduledEventUser"]):
...
Expected: The ScheduledEventUser
import should not be removed
Actual behavior: ScheduledEventUser
gets removed even though it is used
(Source file for context - https://github.com/nextcord/nextcord/blob/master/nextcord/iterators.py)
Issue Analytics
- State:
- Created a year ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Python generic that adds typed functionality to extend existing ...
The first solution will make autocomplete almost happy: from __future__ import annotations from typing import Callable, Generic, Set, Type, ...
Read more >The `if TYPE_CHECKING` problem · Issue #1 - GitHub
My only idea for a solution is to make an undefined name produce some special object, like typing.ForwardRef , in an annotation.
Read more >Common issues and solutions - mypy 0.991 documentation
There are several common reasons why obviously wrong code is not flagged as an error. The function containing the error is not annotated....
Read more >typing — Support for type hints — Python 3.11.1 documentation
A user-defined class can be defined as a generic class. from typing import TypeVar, Generic from logging ...
Read more >Java Generics Example Tutorial - Generic Method, Class ...
If we don't provide the type at the time of creation, the compiler will produce a warning that “GenericsType is a raw type....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hmmm that’s surprising. I definitely have code in that style at work and don’t run into this issue. I’ll investigate it. Thanks for reporting!
Gotcha, yeah I think that’s our best option for now.