Skip to content

typing: allow union types for instance_of - #1385

Merged
hynek merged 5 commits into
mainfrom
instance-of-union
Dec 15, 2024
Merged

hynek merged 5 commits into
mainfrom
instance-of-union

Conversation

@hynek

@hynek hynek commented Dec 14, 2024

Copy link
Copy Markdown
Member

fixes #1336

@hynek
hynek requested a review from Tinche December 14, 2024 13:27
@hynek

hynek commented Dec 14, 2024

Copy link
Copy Markdown
Member Author

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

Tinche commented Dec 14, 2024

Copy link
Copy Markdown
Member

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
@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