-
-
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
Type annotations on md5
, sha1
, and sha256
should be overloaded
#2046
Comments
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. |
Before this change, the return type for these functions was always `bytes| str`. However, the type can be narrowed based on the value passed to `raw_output`. This change adds overload annotations for the two allowable values to allow type checkers to narrow the type and correctly infer the exact return type. Resolves joke2k#2046
If I'm still in time to catch this train - the same applies to uuid4(), which has a return type of |
the |
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 |
I dont see any issues with falling back to |
Before this change, the return type for these functions was always `bytes| str`. However, the type can be narrowed based on the value passed to `raw_output`. This change adds overload annotations for the two allowable values to allow type checkers to narrow the type and correctly infer the exact return type. Resolves joke2k#2046
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?
The text was updated successfully, but these errors were encountered: