chadrik / typewriter

Insert PEP 484 type annotations into your source code
Apache License 2.0
7 stars 2 forks source link

check if type we're trying to find is in the current module, before searching for import #3

Open pmolodo opened 3 years ago

pmolodo commented 3 years ago

If we are currently updating the contents of mod1.py, and a function signature uses mod1.MyClass as one of it's types, then we should skip searching for an import of mod1.MyClass.

Right now, this mostly works, because the search for mod1.MyClass inside of mod1 will generally fail - which means it will try to create an import statement... but then add_import filters out anything trying to import the current module.

At best, this is inefficient (we don't need to bother searching for mod1.MyClass), and at worst, we might get incorrect results - for instance, if we have modules with "doubled names" - ie, versions.versions.