Skip to content

sys.version_info check fails with --fast-parser #1708

New issue

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

By clicking “No 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? No Sign in to your account

Closed
sharmaeklavya2 opened this issue Jun 14, 2016 · 2 comments
Closed

sys.version_info check fails with --fast-parser #1708

sharmaeklavya2 opened this issue Jun 14, 2016 · 2 comments

Comments

@sharmaeklavya2
Copy link

mypy --fast-parser -c "import urllib.request" outputs:

<string>:1: note: In module imported here:
.../lib/mypy/typeshed/stdlib/3/urllib/request.pyi: note: In class "Request":
.../lib/mypy/typeshed/stdlib/3/urllib/request.pyi:36: error: Callable[[Request], str] has no attribute "setter"

I looked at the relevant code in typeshed/stdlib/3/urllib/request.pyi:

class Request:
    if sys.version_info >= (3, 4):
        @property
        def full_url(self) -> str: ...
        @full_url.setter
        def full_url(self, value: str) -> None: ...
        @full_url.deleter
        def full_url(self) -> None: ...
    else:
        full_url = ...  # type: ignore # type: str

I use python 3.4. I removed the version check like this:

class Request:
    @property
    def full_url(self) -> str: ...
    @full_url.setter
    def full_url(self, value: str) -> None: ...
    @full_url.deleter
    def full_url(self) -> None: ...

Then there was no error message.

It looks like mypy's fast parser is having trouble with the version check.

@sharmaeklavya2
Copy link
Author

sharmaeklavya2 commented Jun 14, 2016

Because of this bug, six.moves cannot be used with --fast-parser in python 3 mode.

@ddfisher
Copy link
Collaborator

Thanks for the bug report! I should have a fix for this shortly.

This isn't actually to do with the fast parser's understanding of version checks. What's actually going on is this: mypy's current parser combines repeated decorated function definitions with the same name into an OverloadedFunctionDef object, without checking if they're actually overloads. The (later) code that understands properties assumes this is the case. The faster parser only does this overload fixup at the top level of class definitions, so it's not happening when you wrap the property in an if statement.

Incidentally, this means that properties won't work properly if the lines aren't contiguous.

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

No branches or pull requests

3 participants