-
Notifications
You must be signed in to change notification settings - Fork 422
fix(python): correct type dispatch in infer_field for custom classes #3432
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
5fd72f7
1a5a0af
26abcde
629a13b
5595d01
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -249,11 +249,17 @@ def infer_field(field_name, type_, visitor: TypeVisitor, types_path=None): | |
| else: | ||
| raise TypeError(f"Collection types should be {list, dict} instead of {type_}") | ||
| else: | ||
| if is_function(origin) or not hasattr(origin, "__annotations__"): | ||
| if is_function(origin): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I do not understand, what does this fix exactly?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previously, types without This caused incorrect type dispatch for custom classes. By removing the Please let me know if I should clarify this further in the PR description. |
||
| return visitor.visit_other(field_name, type_, types_path=types_path) | ||
| else: | ||
|
|
||
| if origin in (list, dict, set): | ||
| return visitor.visit_other(field_name, type_, types_path=types_path) | ||
|
|
||
| if inspect.isclass(origin) and origin.__module__ not in ("builtins", "datetime"): | ||
| return visitor.visit_customized(field_name, type_, types_path=types_path) | ||
|
|
||
| return visitor.visit_other(field_name, type_, types_path=types_path) | ||
|
|
||
|
|
||
| def is_function(func): | ||
| return inspect.isfunction(func) or is_cython_function(func) | ||
|
|
||
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.
This may be wrong, only dataclass should be taken as struct. The current struct seiralizer is DataclassSerializer and it only support dataclass too