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

(regression: 1.5.1) mypy thinks TypeVar bound to DataclassInstance is not bound to dataclass #16155

Closed
JSS95 opened this issue Sep 21, 2023 · 1 comment
Labels
bug mypy got something wrong

Comments

@JSS95
Copy link

JSS95 commented Sep 21, 2023

Bug Report

TypeVar("T", bound=DataclassInstance) is clearly bound to dataclass, but mypy thinks otherwise.

To Reproduce

import dataclasses
from typing import TypeVar, Generic, TYPE_CHECKING

if TYPE_CHECKING:
    from _typeshed import DataclassInstance


T = TypeVar("T", bound=DataclassInstance)


class MyGeneric(Generic[T]):
    Dcls: T

    def foo(self) -> T:
        return dataclasses.replace(self.Dcls)

mypy playground link

Expected Behavior

mypy check should pass. (It was OK until 1.4.1)

Actual Behavior

main.py:15: error: Argument 1 to "replace" has a variable type "T" not bound to a dataclass  [misc]
Found 1 error in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: 1.5.1
  • Mypy command-line flags: no flag
  • Mypy configuration options from mypy.ini (and other config files): no config
  • Python version used: 3.11.5
@JSS95 JSS95 added the bug mypy got something wrong label Sep 21, 2023
@JSS95 JSS95 changed the title mypy thinks TypeVar bound to DataclassInstance is not bound to dataclass (regression: 1.5.1) mypy thinks TypeVar bound to DataclassInstance is not bound to dataclass Sep 21, 2023
@JSS95 JSS95 changed the title (regression: 1.5.1) mypy thinks TypeVar bound to DataclassInstance is not bound to dataclass (regression: 1.5.0) mypy thinks TypeVar bound to DataclassInstance is not bound to dataclass Sep 21, 2023
@JSS95 JSS95 changed the title (regression: 1.5.0) mypy thinks TypeVar bound to DataclassInstance is not bound to dataclass (regression: 1.5.1) mypy thinks TypeVar bound to DataclassInstance is not bound to dataclass Sep 21, 2023
@AlexWaygood
Copy link
Member

AlexWaygood commented Sep 21, 2023

Duplicate of #15843. Fixed by #15962 and #15915. The fixes probably won't make it into mypy 1.6, but should make it into mypy 1.7.

@AlexWaygood AlexWaygood closed this as not planned Won't fix, can't repro, duplicate, stale Sep 21, 2023
DeadNews added a commit to DeadNews/dnfunc that referenced this issue Sep 28, 2023
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

2 participants