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

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

Closed
efroemling opened this issue Mar 7, 2023 · 2 comments
Closed

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

efroemling opened this issue Mar 7, 2023 · 2 comments

Comments

@efroemling
Copy link

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.

@AlexWaygood
Copy link
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.

@srittau
Copy link
Collaborator

srittau commented Mar 8, 2023

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

@srittau srittau closed this as not planned Won't fix, can't repro, duplicate, stale Mar 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants