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

(🐞) New union syntax inconsistent with old union syntax, now it contains Any #12224

Closed
KotlinIsland opened this issue Feb 21, 2022 · 3 comments
Labels
bug mypy got something wrong topic-disallow-any The disallow-any-* family of flags topic-pep-604 PEP 604 (union | operator) topic-union-types

Comments

@KotlinIsland
Copy link
Contributor

KotlinIsland commented Feb 21, 2022

from typing import Union
class A:
    def __init__(self, a): ...
    
Test1 = str | A  # error
Test2 = Union[str, A]

main.py:5: error: Expression type contains "Any" (has type "Type[A]")
But no error on the last line

https://mypy-play.net/?mypy=latest&python=3.10&flags=disallow-any-expr&gist=dd6dcaf336fb58d4afc3310200259630

@KotlinIsland KotlinIsland added the bug mypy got something wrong label Feb 21, 2022
@ktbarrett
Copy link

I think the issue is that it is not considering the type A as typed since the __init__ is not typed.

The following passes without issue.

from typing import Union

class A:
    def __init__(self, a: int) -> None: ...
    
Test1 = str | A
Test2 = Union[str, A]

@AlexWaygood AlexWaygood added topic-pep-604 PEP 604 (union | operator) topic-disallow-any The disallow-any-* family of flags labels Mar 24, 2022
@erictraut
Copy link

This bug was apparently fixed in mypy 1.0.0. I think it can be closed.

@hauntsaninja
Copy link
Collaborator

Fixed in #14181

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-disallow-any The disallow-any-* family of flags topic-pep-604 PEP 604 (union | operator) topic-union-types
Projects
None yet
Development

No branches or pull requests

6 participants