Skip to content

Allow covariant attributes for frozen data classes in Python 3.13+ #21736

Description

@christophgietl

Bug Report

When defining a frozen data class with a covariant attribute using TypeVar syntax, mypy says I cannot use a covariant type variable as a parameter.

To Reproduce

https://gist.github.com/mypy-play/b0220af57a90126d77c4cdf83726e75d

Expected Behavior

mypy does not report any errors.

Actual Behavior

main.py:8: error: Cannot use a covariant type variable as a parameter  [misc]
Found 1 error in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: 2.3.0
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.13

Side Note

When using type parameter syntax, mypy infers frozen data class attributes as covariant since #21694:
https://gist.github.com/mypy-play/9fc4154d2c63f64c8a0ddbe85c2ac660

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions