Skip to content

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

Closed

Description

@sharmaeklavya2

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.

Activity

  1. sharmaeklavya2 commented on Jun 14, 2016

    @sharmaeklavya2
    Author

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

  2. ddfisher commented on Jun 15, 2016

    @ddfisher
    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.

  3. added a commit that references this issue on Jun 21, 2016
    ef5e7c5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions