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

typing: allow union types for instance_of #1385

Merged
merged 5 commits into from
Dec 15, 2024
Merged

typing: allow union types for instance_of #1385

merged 5 commits into from
Dec 15, 2024

Conversation

hynek
Copy link
Member

@hynek hynek commented Dec 14, 2024

fixes #1336

@hynek hynek requested a review from Tinche December 14, 2024 13:27
@hynek
Copy link
Member Author

hynek commented Dec 14, 2024

Tiiiiin, is this fixableeeee?

tests/typing_example.py:231: error: Incompatible types in assignment (expression has type "UnionType", variable has type "int | C | str")
[assignment]
        kk: int | C | str = attr.ib(
                            ^
Found 1 error in 1 file (checked 1 source file)

Or are we doing typing bankruptcy (aka Any)?

@Tinche
Copy link
Member

Tinche commented Dec 14, 2024

I played around with this a little. I don't think the type system can do this. The overload should be:

@overload
def instance_of(type: UnionType) -> _ValidatorType[Any]: ...

@hynek hynek force-pushed the instance-of-union branch from 82f4087 to 275bb9c Compare December 15, 2024 05:34
@hynek hynek merged commit d3f320e into main Dec 15, 2024
17 checks passed
@hynek hynek deleted the instance-of-union branch December 15, 2024 05:45
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

Successfully merging this pull request may close these issues.

Mypy false positive for union validator
2 participants