Skip to content

Mypy treating type of final class variable in dataclass as Any #21906

Description

@ipilcher

Bug Report

from dataclasses import dataclass
from typing import ClassVar, Final, reveal_type

class Bar: pass

@dataclass
class Foo:
    cv: ClassVar[Final[dict[type[Bar], Foo]]] = {}

reveal_type(Foo.cv)
$ mypy test.py
test.py:10: note: Revealed type is "Any"
Success: no issues found in 1 source file

The correct type of Foo.cv is builtins.dict[type[Bar], Foo].

To Reproduce

https://mypy-play.net/?mypy=latest&python=3.14&gist=2fad4ef5fded90ecaeb0f1d1e59d882a

Expected Behavior

reveal_type should report the correct type for the class variable.

Actual Behavior

reveal_type showed incorrect type (Any).

Your Environment

  • Fedora 44
  • python3-mypy-1.18.2-4.fc44.noarch (reproducible with Mypy 2.3.1)
  • python3-3.14.6-1.fc44.x86_64
  • No config files used

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