-
-
Notifications
You must be signed in to change notification settings - Fork 148
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
Inline some types #221
Merged
Merged
Inline some types #221
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
da7aa65
Move type annotations into masks.py
jaraco 7a15cd1
⚫ Fade to black.
jaraco 6fb137a
🧎♀️ Genuflect to the types.
jaraco 1465f6a
Move 'overload' types inline.
jaraco eed813b
Merge branch 'main' into feature/inline-types
jaraco bbbd30c
🚡 Toil the docs.
jaraco e608ef6
Add news fragment.
jaraco File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Inlined some types. |
This file contains 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To reduce runtime overhead, you could move all the overloads into an
if TYPE_CHECKING
block too.It will
typing.overload
import into type checking imports, keeping it away from the runtime variable namespacewhile still working out well in type checking. Similarly for other overloads.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You know what would be even nicer is if the type system provided a way to indicate that a function or method is a wrapper around another function/method and takes the exact same or slightly altered arguments, something like:
Then, a reader of this could wouldn't be accosted by the copy-pasta from the upstream implementation and the type system could readily reflect the overloaded types.
Or even better, make that the default behavior, so that if no type signature is applied, the signature is implied by the way it's used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Proposed in #224. Is that what you meant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is something like
typing.reflect
already, but it's not a well-documented feature :) Namely,functools.wraps
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason I think it's a type-checking equivalent of our
typing.reflect
is thatfunctools.wraps
takes a callable of signatureP
and the wrapper is then typed to be of signatureP
too.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, gonna reply there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm familiar with functools.wraps, but I've not seen it used except for it's documented primary purpose (wrapping a function in a decorator). I've created #225 to explore that possibility.