Skip to content

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

Closed as not planned
@efroemling

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.

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