Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

ParseError: Invalid type comment: (__main__:f.<locals>.A) -> None #92

Open
blueyed opened this issue Nov 20, 2019 · 2 comments
Open

ParseError: Invalid type comment: (__main__:f.<locals>.A) -> None #92

blueyed opened this issue Nov 20, 2019 · 2 comments
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()


def c(obj):
    pass


def f():
    class A:
        pass

    c(A())


f()

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

Produces:

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

Running pyannotate -w then crashes:

Traceback (most recent call last):
  File "…/Vcs/pytest/.venv/bin/pyannotate", line 11, in <module>
    load_entry_point('pyannotate', 'console_scripts', 'pyannotate')()
  File "…/Vcs/pyannotate/pyannotate_tools/annotations/__main__.py", line 125, in main
    data = generate_annotations_json_string(
  File "…/Vcs/pyannotate/pyannotate_tools/annotations/main.py", line 60, in generate_annotations_json_string
    signature = unify_type_comments(item.type_comments)
  File "…/Vcs/pyannotate/pyannotate_tools/annotations/main.py", line 27, in unify_type_comments
    arg_types, return_type = infer_annotation(type_comments)
  File "…/Vcs/pyannotate/pyannotate_tools/annotations/infer.py", line 45, in infer_annotation
    arg_types, return_type = parse_type_comment(comment)
  File "…/Vcs/pyannotate/pyannotate_tools/annotations/parse.py", line 216, in parse_type_comment
    return Parser(comment).parse()
  File "…/Vcs/pyannotate/pyannotate_tools/annotations/parse.py", line 225, in __init__
    self.tokens = tokenize(comment)
  File "…/Vcs/pyannotate/pyannotate_tools/annotations/parse.py", line 193, in tokenize
    raise ParseError(original)
pyannotate_tools.annotations.parse.ParseError: Invalid type comment: (__main__:f.<locals>.A) -> None

This is likely due to the "" in there I guess?

pyannotate b7f96ca (current master)

@JukkaL
Copy link

JukkaL commented Nov 21, 2019

The nested class seems to cause the trouble. We could use a short name for the nested class type, or perhaps just filter them out at some point.

@hofrob
Copy link

hofrob commented Jan 3, 2023

Is it safe to assume that this project is abandoned? This is a major bug which makes this tool unusable. At least I can't figure out a way around this without just manually processing the generated json.

Please archive it and adapt the readme to prevent further headaches.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants