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

Incorrect ParseError for type comment in unexpected location #53

Closed
JelleZijlstra opened this issue Mar 18, 2017 · 6 comments
Closed

Incorrect ParseError for type comment in unexpected location #53

JelleZijlstra opened this issue Mar 18, 2017 · 6 comments

Comments

@JelleZijlstra
Copy link
Contributor

From https://travis-ci.org/python/typeshed/jobs/212532837:

Running pytype tests...
pytd error processing "stdlib/2and3/cgi.pyi":
  File: "stdlib/2and3/cgi.pyi", line 107
    def values(self, key: Any) -> Any: ...  # type: ignore
                                            ^
ParseError: syntax error, unexpected TYPECOMMENT, expecting DEF or '@'

Type comments should be allowed here.

@matthiaskramm
Copy link
Contributor

matthiaskramm commented Mar 20, 2017

You need the type: ignore for disabling mypy's check, for methods being compatible with their superclass's methods?

Maybe we need a # mypy: ignore, after all. See python/typed_ast#14

@gvanrossum
Copy link

Only # type: ignore should be allowed virtually anywhere. Type comments expressing types are only allowed in specific places (though the spec is probably a bit vague -- IIRC typed_ast just picked a set of rules that are good enough).

But I'm also fine with just working around this in typeshed by moving the ... to the next line.

@JelleZijlstra
Copy link
Contributor Author

Moving ... to the next line still generates a parse error in pytype.

@gvanrossum
Copy link

Oh, that's unfortunate. But I do think that this is not just a mypy-specific thing. Liskov substitutability is taken pretty seriously by PEP 484. (It's the reason we have to declare variance.)

@matthiaskramm
Copy link
Contributor

Fair enough. We'll add #type: ignore after function signatures to the pytype parser.

@matthiaskramm
Copy link
Contributor

Fix pushed.

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

No branches or pull requests

3 participants