Skip to content

type not generic when running with Python < 3.9 #10303

Closed

Description

@srittau

Bug Report

Please consider the following stub file:

x: dict[str, str]
y: type[str]

When checking it with mypy 0.820+dev.1e96f1df48a6e06ba598fa8230b96671b206cba0 and Python 3.9.4, it passes. Using Python 3.8.9 on the other hand, produces the following output:

foo.pyi:2: error: "type" expects no type arguments, but 1 given

It's weird that generic dict works, but generic type doesn't. (Although I'd expect both to work with any Python version.)

This came up during python/typeshed#5192.

Activity

  1. added a commit that references this issue on Jul 5, 2021
    6eafc5e
  2. srittau commented on Dec 22, 2021

    @srittau
    ContributorAuthor

    @JukkaL This doesn't seem to fixed in mypy 0.930:

    $ mypy --version
    mypy 0.930
    $ cat foo.pyi 
    x: dict[str, str]
    y: type[str]
    $ mypy --python-version=3.9 foo.pyi 
    Success: no issues found in 1 source file
    $ mypy --python-version=3.8 foo.pyi 
    foo.pyi:2: error: "type" expects no type arguments, but 1 given
    Found 1 error in 1 file (checked 1 source file)
    

    (I tested it with both Python 3.9.6 and 3.6.14.)

  3. AlexWaygood commented on Dec 28, 2021

    @AlexWaygood
    Member

    @JukkaL This doesn't seem to fixed in mypy 0.930:

    Interestingly, it appears to be fixed for .py files, but not for .pyi files. This, in a .py file, will pass using Python 3.7:

    from __future__ import annotations
    foo: type[str]

    But this, in a .pyi file, fails using Python <= 3.8:

    foo: type[str]

    Many similar errors can be found in the CI output for python/typeshed#6681.

  4. AlexWaygood commented on Dec 28, 2021

    @AlexWaygood
    Member
  5. sobolevn commented on Dec 29, 2021

    @sobolevn
    Member

    Sorry, I cannot not reopen issues, but here's my PR: #11863

  6. hauntsaninja commented on Jan 6, 2022

    @hauntsaninja
    Collaborator

    Thanks to sobolevn this should be fixed for pyi with old Pythons!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions