Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Creates "from __main__" import for __main__ program #93

Open
blueyed opened this issue Nov 20, 2019 · 1 comment
Open

Creates "from __main__" import for __main__ program #93

blueyed opened this issue Nov 20, 2019 · 1 comment
Labels

Comments

@blueyed
Copy link
Contributor

blueyed commented Nov 20, 2019

Given t-pyannotate.py:

from pyannotate_runtime import collect_types


collect_types.init_types_collection()
collect_types.start()


class G:
    pass


def c(obj):
    pass


c(G())

collect_types.stop()
collect_types.dump_stats("type_info.json")

Running and writing it produces the following diff, where it tries to import G from __main__ then:

--- t-pyannotate.py     (original)
+++ t-pyannotate.py     (refactored)
@@ -1,4 +1,5 @@
 from pyannotate_runtime import collect_types
+from __main__ import G


 collect_types.init_types_collection()
@@ -10,6 +11,7 @@


 def c(obj):
+    # type: (G) -> None
     pass

type_info.json:

[
    {
        "path": "t-pyannotate.py",
        "line": 8,
        "func_name": "G",
        "type_comments": [
            "() -> None"
        ],
        "samples": 1
    },
    {
        "path": "t-pyannotate.py",
        "line": 12,
        "func_name": "c",
        "type_comments": [
            "(__main__.G) -> None"
        ],
        "samples": 1
    }
]

pyannotate b7f96ca (current master).

@JukkaL
Copy link

JukkaL commented Nov 21, 2019

This can sometimes be worked around by not running t-pyannotate.py directly and instead importing from another module that you run.

@JukkaL JukkaL added the bug label Nov 21, 2019
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants