Closed samueljsb closed 2 weeks ago
Thank you so much, that would be wonderful!
I've tried to do this but I'm having trouble with the stub files. They don't seem to match the type annotations I put in the actual Python modules (even after running the stub generation script) and manually editing them gets undone when I run the linters.
EDIT: the stub generation doesn't appear to be running in CI, so that isn't a blocker, but it does mean we run the risk of this regressing.
If I'm still in time to catch this train - the same applies to uuid4(), which has a return type of str | bytes | UUID
, and the actual type returned is similarly controlled by a function parameter. https://github.com/joke2k/faker/issues/2042
the generate_stubs.py
script will need to be updated to detect overloads, but typing.get_overloads()
is only available in Python 3.11, and we need to support at least 3.8.
It's in typing_extensions if that's any help for pre-3.11. The trouble is it that pre-3.11 it only detects overloads defined using typing_extensions.overload
, not typing.overload
.
I dont see any issues with falling back to typing_extension
on <3.11. Do you want to try to update generate_stubs.py
to use get_overloads()
?
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.
The docstrings for these functions state:
But the type annotations do not reflect this:
The revealed types ought to be
builtins.str
andbuiltins.bytes
respectively.I believe this can be achieved by overloading the type annotations on those methods (using
typing.overload
.I would be happy to open a PR to make those changes, if that would be welcome?