Visitar URL original
MyPy does not support subclassing function a argument member with type `type` though pyright does (e.g. pyright 1.1.414) · Issue #22337 · python/mypy · GitHub
Skip to content

MyPy does not support subclassing function a argument member with type type though pyright does (e.g. pyright 1.1.414) #22337

Open

Description

@willy-b

Hello MyPy team. Thanks for the great tool.
Sharing the following behavior which appears inconsistent with handling of arguments of type type (normally can be subclassed) and which is inconsistent with the other popular typechecker Pyright (e.g. commandline pyright 1.1.414 ; or latest on pyright-play.net )

Bug Report

MyPy does not support subclassing function a argument member with type type though pyright does.

Consider the following example in the Pyright playground (typechecks there):
Code sample in pyright playground

class Person():
    def __init__(self, name: str, age: int, characteristics: type):
      self.name = name
      self.age = age
      self.characteristics = characteristics

def foo(person: Person) -> None:
    reveal_type(person.characteristics)
    class Sub(person.characteristics): pass
Image

If one attempts the same in MyPy 2.4.1
MyPy produces an error attempting to subclass person.characteristics though MyPy recognizes the type as builtins.type:
https://mypy-play.net/?mypy=2.4.1&python=3.12&gist=0ecda4fd36c9338c128ae16e69750463

class Person():
    def __init__(self, name: str, age: int, characteristics: type):
      self.name = name
      self.age = age
      self.characteristics = characteristics

def foo(person: Person) -> None:
    reveal_type(person.characteristics) # N: Revealed type is "builtins.type"
    class Sub(person.characteristics): pass

output:

main.py:8: note: Revealed type is "type"
main.py:9: error: Name "person.characteristics" is not defined  [name-defined]

(MyPy reveals the type of person.characteristics successfully but says the name is undefined when attempting to subclass)

Image

(And the same on the latest master

Image )

This is despite subclassing arguments of type type being generally supported, e.g.
https://mypy-play.net/?mypy=latest&python=3.12&gist=40c549b7acb527d213518171db016ca7

def foo(a_type: type) -> None:
    reveal_type(a_type) # N: Revealed type is "builtins.type"
    class Sub(a_type): pass

is fine in MyPy 2.4.1 .

Image

Thanks!

Your Environment

Thanks

Activity

  1. added a commit that references this issue on Nov 4, 2026
    8a02ccb
  2. willy-b commented on Nov 12, 2026

    @willy-b
    ContributorAuthor
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