dropbox / pyannotate

Auto-generate PEP-484 annotations

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`No files need to be modified.` when `__init__.py` exists

dhallam opened this issue · comments

Running python 2.7.11 with pyannotate v1.0.3 installed in a virtualenv on ubuntu 16.0.4. I cloned this repo and ran the following

cd example
python driver.py
pyannotate gcd.py

This resulted in the expected

Refactored gcd.py
--- gcd.py	(original)
+++ gcd.py	(refactored)
@@ -1,8 +1,10 @@
 def main():
+    # type: () -> None
     print(gcd(15, 10))
     print(gcd(45, 12))
 
 def gcd(a, b):
+    # type: (int, int) -> int
     while b:
         a, b = b, a%b
     return a
Files that need to be modified:
gcd.py
NOTE: this was a dry run; use -w to write files

If I then create an __init__.py file, and run pyannotate gcd.py, I get

No files need to be modified.
NOTE: this was a dry run; use -w to write files

which is not what I expect to get. This is preventing me from running across my project's codebase. The type_info.json file is created correctly. It's the pyannotate step that fails to identify any changes.

pipdeptree output showing what is installed

  - mypy-extensions [required: Any, installed: 0.3.0]
  - six [required: Any, installed: 1.11.0]
  - typing [required: >=3.5.3, installed: 3.6.4]

This is likely because you're running pyannotate from inside the package. You shouldn't do that. Or you should delete the unneeded toplevel __init__.py file. Check out the function crawl_up() to understand.

@gvanrossum That makes perfect sense. We had a stray __init__.py in our root folder causing the issue. All is working well now. Many thanks for a great tool.