Thanks to visit codestin.com
Credit goes to github.com

Skip to content

dataclass(frozen=True) not working with default Final qualifier #18567

Description

@mflova

Bug Report

When using Final type hint in combination with dataclass(frozen=True), mypy displays an error. This error disappears either if frozen=True is removed or the type of Final is provided.

To Reproduce

from dataclasses import dataclass
from typing import Final


@dataclass
class Foo:
    var: Final = "a"

@dataclass(frozen=True)
class Foo2:
    var: Final = "a"

@dataclass(frozen=True)
class Foo3:
    var: Final[str] = "a"

foo = Foo()
foo.var  # OK

foo2 = Foo2()
foo2.var  # ERROR: "Foo" not callable [operator]

foo3 = Foo3()
foo3.var  # OK

Your Environment

  • Mypy version used: 1.14.1
  • Mypy command-line flags: mypy script.py
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.10.11

Activity

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions