-
-
Notifications
You must be signed in to change notification settings - Fork 34.4k
GH-100623: Implement singledispatch on type/class arguments #100624
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
Closed
smheidrich
wants to merge
11
commits into
python:main
from
smheidrich:fix-gh-100623-1-singledispatch-type-args
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d2d09c1
Implement singledispatch on type arguments POC
smheidrich 31e1ae6
Fix wrapping MRO classes in type[...] if necessary
smheidrich b874773
Add support for Type[X] instead of just type[X]
smheidrich 78d25ce
Add test for and fix default func for type arg
smheidrich 1ec0ad4
Use set instead of generator for registry_classes
smheidrich 7da2946
Implement support for type[A|B] unions
smheidrich b5171c5
Implement type[A]|type[B] union types
smheidrich 9761b56
Add tests for invalid type[X] types
smheidrich eb23d05
Split up tests
smheidrich 8a648bc
📜🤖 Added by blurb_it.
blurb-it[bot] 2183609
Replace unnecessary isclass w/ isinstance( , type)
smheidrich 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 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
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
1 change: 1 addition & 0 deletions
1
Misc/NEWS.d/next/Library/2022-12-30-15-21-50.gh-issue-100623.3hdA1o.rst
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Add support for dispatching on ``type[...]`` arguments to :func:`functools.singledispatch`. |
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.
Uh oh!
There was an error while loading. Please reload this page.
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 wondering if treating
type[a|b]andtype[a]|type[b]the same actually makes sense and even if so, whether union types should be supported fortype[...]arguments at all:E.g. if we have a single-dispatch function with an implementation for
type[a|b|c], wouldn't people expect to be able to pass e.g.a|bto it and have it dispatch to that implementation? That would be much harder to implement than my current naive implementation of just splitting up unions into their individual constituent types, especially consideringissubclass(a|b, a|b|c)isn't even possible.So maybe unions of
type[...]s andtype[...]s of unions should just not be allowed for now, deferring them to when (if ever)issubclasssupports these kinds of checks (or Python gets anotherissubtypefunction).OTOH, it's unlikely that introducing support for dispatching to
type[a|b|c]givena|blater on would be much of a breaking change... If only dispatching on single types is supported for now then that is all people will use, nobody will rely on the fact thata|bdispatches to the default implementation, they'll just never passa|bto a single-dispatch function in the first place I should think. So it might be fine to implement it like this for now and leave only the "proper" handling for later.