question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Imports removed incorrectly with Generic class type annotation

See original GitHub issue

Example 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:closed
  • Created a year ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
fsouzacommented, Oct 22, 2022

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!

0reactions
fsouzacommented, Oct 24, 2022

Gotcha, yeah I think that’s our best option for now.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found