Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mypy throws wrong assignment error in dataclasses.__post_init #18735

Open
Felixoid opened this issue Feb 25, 2025 · 0 comments
Open

mypy throws wrong assignment error in dataclasses.__post_init #18735

Felixoid opened this issue Feb 25, 2025 · 0 comments
Labels
bug mypy got something wrong

Comments

@Felixoid
Copy link
Contributor

Bug Report

mypy fails to proceed a known dataclass field, considering it's a list[object], see the reproduce script and the output

To Reproduce

from dataclasses import dataclass
from pathlib import Path
from typing import Sequence, Union


@dataclass
class TestCase:
    files: Union[Sequence[str], Sequence[Path]]

    def __post_init(self) -> None:
        self.files = sorted(
            self.files, key=lambda x: str(x).rsplit("/", maxsplit=1)[-1]
        )

Expected Behavior

There shouldn't be errors

Actual Behavior

> mypy .
mypy_fail.py:11: error: Incompatible types in assignment (expression has type "list[object]", variable has type "Sequence[str] | Sequence[Path]")  [assignment]

Your Environment

  • Mypy version used: mypy 1.14.0 (compiled: no)
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.13.2

In the scope of ClickHouse/ClickHouse#76679

@Felixoid Felixoid added the bug mypy got something wrong label Feb 25, 2025
@Felixoid Felixoid changed the title mypy throws assignment error in dataclasses.__post_init mypy throws wrong assignment error in dataclasses.__post_init Feb 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

1 participant