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

Union normalized to object when Type requested #9830

Closed
Gricha opened this issue Dec 22, 2020 · 1 comment
Closed

Union normalized to object when Type requested #9830

Gricha opened this issue Dec 22, 2020 · 1 comment
Labels
bug mypy got something wrong

Comments

@Gricha
Copy link

Gricha commented Dec 22, 2020

Bug Report

Here's the code snippet:

import typing as t

class Entity(t.Protocol):
    ...

class Foo(Entity):
    ...

class Bar(Entity):
    ...

def foo(a: t.Type[Entity]) -> None:
    ...

foo(t.Union[Foo, Bar, ])

In our code we have some use cases, where we use the type to mark, say, where the exception is happening. The code here only knows that the type will be following a specific protocol (Entity), but at call site we only know a union of possible concrete types.

The code specifically that we have can be worked around, but I wondered whether the behavior change is intended or an accidental bug. We've leveraged it and it worked so far up to 0.770. In 0.780 and 0.790 that code snippet will throw an error:

example_test.py:18: error: Argument 1 to "foo" has incompatible type "object"; expected "Type[Entity]"
Found 1 error in 1 file (checked 1 source file)

Which looks like the Union has been normalized to an object which seems incorrect.

@Gricha Gricha added the bug mypy got something wrong label Dec 22, 2020
@hauntsaninja
Copy link
Collaborator

Duplicate of #9773 (see linked issues)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

2 participants