Skip to content

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

Closed as not planned

Description

@JSS95

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

Activity

  1. 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[/+] on Sep 21, 2023
  2. 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[/+] on Sep 21, 2023
  3. 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[/+] on Sep 21, 2023
  4. AlexWaygood commented on Sep 21, 2023

    @AlexWaygood
    Member

    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.

  5. added a commit that references this issue on Sep 28, 2023
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

    bugmypy got something wrong

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions