FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

typing: allow union types for instance_of by hynek · Pull Request #1385 · python-attrs/attrs · GitHub

typing: allow union types for instance_of - #1385

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

typing: allow union types for instance_of#1385
hynek merged 5 commits into
mainfrom
instance-of-union

Conversation

hynek commented Dec 14, 2024

Copy link
Copy Markdown
Member

fixes #1336

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

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 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 force-pushed the instance-of-union branch from 82f4087 to 275bb9c Compare December 15, 2024 05:34
hynek merged commit d3f320e into main Dec 15, 2024
hynek deleted the instance-of-union branch December 15, 2024 05:45
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL