-
Notifications
You must be signed in to change notification settings - Fork 44
Fixing typing syntax error in python 3.10 #1307
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: master
Are you sure you want to change the base?
Conversation
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.
using:
return Annotated[base_type, old_metadata, new_metadata]
will alter the behavior of the method and is not equivalent to:
return Annotated[base_type, *old_metadata, new_metadata]
am not sure if your solution will unpack the old_metadata
variable which is a list
.
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 agree with @MichaelDecent here.
@VijayVignesh1 do you have any logs or screenshots of unexpected behavior that you've observed? |
@MichaelDecent Oh I get it! Just to make sure, the old_metadata is a list and new_metadata has to be added to the list, right? If you can give me an example, that'd help me better. Thanks! |
@cobycloud Here is the screenshot of the error. |
@MichaelDecent I think the below line should work for all three python versions. It uses class_getitem method to add metadata. The old metadata is also unpacked. |
@cobycloud @MichaelDecent I've updated the code to include Annotated.class_getitem instead of Annotated. Please have a look and let me know if this works. |
@@ -65,12 +65,12 @@ def _add_metadata(self, annotated_type: Any, new_metadata: Any) -> Any: | |||
hasattr(annotated_type, "__origin__") | |||
and annotated_type.__origin__ is Annotated | |||
): | |||
return Annotated[annotated_type, new_metadata] | |||
return Annotated.__class_getitem__((annotated_type, new_metadata)) |
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 don't think this line change is necessary.
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 reverted the line. Please check.
Files Changed:
pkgs/typing/swarmauri_typing/UnionFactory.py