Closed chadrik closed 4 years ago
I looked into writing tests for this, but the test case base class from lib2to3 that’s in use here appears to be designed to test before-and-after code snippets. We would need something higher level that tested runs across multiple files. Having tests at that level would be great but it’s an order of magnitude more work, and I’m not sure I’ll have time for it. I’ll see if there is an existing test case from lib2to3 that we can use for this purpose, just to get a sense of the scope.
Alternately I can write a super simple test function that demonstrates that calling set_filename on an instance of the fixer class updates the current module. Is that what you had in mind?
Yes please, we can still write regular tests.
Ok, added a test that confirms that our overridden set_filename
is called. That should give us a reasonable assurance that the module will be set.
Hm, it looks like I'm no longer on the team that can merge PRs on this repo. Hopefully @msullivan or @JukkaL can still do it?
FixAnnotateJson.current_module
is currently a constant value set in__main__
, but this causes bugs when pyannotate is run on a package directory, where the current module should be updated for each file that is parsed.To fix this, I implemented
set_filename
, which is inherited fromBaseFix
, to update the current module each time the file changes.To test, I removed the annotation from
parse_type_comment
and created atype_info.json
file to provide the type data:I saw two types of bugs with the current implementation.
1) imports statements were added that imported types from the current module:
2) If I passed two packages on the command line the second would be completely ignored.