Skip to content

dataclasses.is_dataclass() assumed always true when passed type #9854

Closed as not planned

Description

@efroemling

Bug Report

In the latest 1.1.1 build of Mypy I've started getting various errors such as 'code is unreachable' or 'statement is always true' around certain uses of dataclasses.is_dataclass(). It seems to happen when the argument to is_dataclass() is a type.

To Reproduce

Here is a playground demonstrating the issue:
https://mypy-play.net/?mypy=master&python=3.11&flags=warn-unreachable&gist=5001f76768535e01b95e69dd2c47a916

If you run it with mypy 1.0.0 it passes, but with mypy master branch it says the 'not-dataclass' path cannot be reached.

The code:

import dataclasses
from typing import Any


def what_is_it(obj: type) -> str:
    if dataclasses.is_dataclass(obj):
        return 'dataclass'

    return 'not-dataclass'

Expected Behavior

Mypy should not assume is_dataclass() always returns True when passed a type.

Actual Behavior

Mypy assumes is_dataclass() always return True when passed a type.

Your Environment

Seeing the error in Mypy 1.1.1 from home-brew on a Mac. 1.1.1 does not seem to be available on the playground but the 'mypy-master-branch' currently exhibits the error.

Activity

  1. AlexWaygood commented on Mar 7, 2023

    @AlexWaygood
    Member

    Apologies for the regression. This has already been fixed in 4ca0c48, but the fix didn't make it into mypy 1.1.1. It's possible mypy will be willing to make a patch release for this.

  2. srittau commented on Mar 8, 2023

    @srittau
    Collaborator

    I'm going to close this here as this seems to be a mypy bug, not related to typeshed.

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions