Import used by type annotation inside __new__ is considered unused

Bug #1670468 reported by Thomas Hauk
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Pyflakes
New
Undecided
Unassigned

Bug Description

An import used by a type annotation inside __new__() in a metaclass is considered unused by flake8/pyflakes/whatever component.

e.g. given:

    from django.db.models import Model

    class SomeMetaclass(type):
        def __new__(mcs, name, bases, attrs):
            model_class_attrs: [(str, Model,)] = []
            model_class_attrs.clear()
            return super().__new__(mcs, name, bases, attrs)

Running flake8 results in the error:

    example.py:1:1: F401 'django.db.models.Model' imported but unused

Versions:

Python 3.6
flake8 3.3.0
mccabe 0.6.1
pycodestyle 2.3.1
pyflakes 1.5.0

Revision history for this message
asmeurer (asmeurer) wrote :

I believe this was fixed here https://github.com/PyCQA/pyflakes/pull/88

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.