dropbox / pyannotate

Auto-generate PEP-484 annotations
Apache License 2.0
1.42k stars 59 forks source link

Fix current module calculation in fixer #81

Closed msullivan closed 5 years ago

msullivan commented 5 years ago

When fixing a file named foo/bar/baz.py where bar does not contain an init.py, we currently calculate that the module is named foo.bar.baz. Then, if something like baz.Spam is included in an annotation, we will erroneously insert an import of baz. Fix this by calculating module name based on the directory crawl (which we already do to find the module root).

This is wrong if the file is supposed to be in a namespace packages, I guess, but I'm pretty sure the existing code is also wrong in that case but in different ways.

The test framework doesn't really seem set up to test this kind of thing, so there isn't a test, but I tested manually.

gvanrossum commented 5 years ago

I added a little bit of infrastructure for integration tests. Can you rebase and add one for this issue?