-
Notifications
You must be signed in to change notification settings - Fork 227
Get default type of hybrid_property from type annotation #333
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
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0382353
Get default type of hybrid_property from type annotation
conao3 058ed3f
use type_ instead of type
conao3 8189813
In modern python, instead of a class, it contains class name
conao3 9d75030
show warnings to inform user that type convertion has failed
conao3 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
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
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.
See my comment in the PR
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 need this feature, so I picked it up to try to finish the work.
Just as a heads up, I tried to use the actual
@singledispatch
mechanism and it is not a very good fit, since we are using actual types from a type annotation, and not values. So the types inside a type annotation usually descend from the basetype
, so@singledispatch
fails to match anything in a meaningful way 😢I'm trying to code an approach similar to that where we can decorate functions and switch based on value or on some kind of matcher function, so it will basically become a glorified (but as you said, customizable by the end user in a very flexible way) switch statement. I foresee we will still need some kind of escape hatch using the 'default' (no match) function to analyze deeper types like List[T] and things like that.
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.
Let me know what you come up with! 😃
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 will, thank you 🙏 I'll open a new Pull Request for #333 from my own fork as soon as I have the basics working.
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 want to finish this work. I will work on this PR tomorrow, so can it wait?
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 am branching by case statement because it returning the corresponding Graphene type in a class of
type
type obtained by__annotations__
.functools.singledispatch
is a way to achieve polymorphism by instance type, but I don't know at this time how to achieve polymorphism by the class itself.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.
Indeed, the standard library's singledispatch approach is inadequate for what we want. I provided a solution using a different type of matching but leaving the comfort/developer a
@singledispatch
-like experience provides.I finished the work I intended and opened a pull request, mentioning this issue in it, looking forward for the review.