-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
uuid4() - become unusuable for safe typing without casting or ignoring #2042
Comments
uuid4
become unusuable for safe typing without casting or ignoring
Feel free to provide a corresponding PR which improves this. |
@stefan6419846 it will require breaking changes, is it okay? I definitely can provide PR for this one |
Can't this be fixed by using some kind of |
Based on the type in the docs:
Like fcurella says, I think it should be possible to overload it like:
Failing that, get rid of T by explicitly listing both possibilities:
I don't think that should be a breaking change. Or potentially you could make the function more general, allowing
|
This issue is stale because it has been open for 30 days with no activity. |
Let me guys try to create MR for this and we can see how far forward we can go with this... |
When using
fake.uuid4()
, the returning type isbytes | str | UUID
which is impossible to safely use later on in the code.I guess one way to solve it to use
literals
instead ofcast_to
callable, as there are limited ways to cast it to. Only 3 types, therefore better to useLiteral
ascast_to
and provide@typing.overload
to properly infer return type from the input param. Also by default it should returnstr
Steps to reproduce
Nypy will produce error as for type checker the value can be either bytes or str or UUID which cannot be joined together. But in runtime here will no be any errors
Expected behavior
No typing errors should be observed
Actual behavior
Using
fake.uuid4()
withouttyping.cast
ortype: ignore
appears impossible after adding the types.The text was updated successfully, but these errors were encountered: