Skip to content

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

VijayVignesh1
Copy link

Files Changed:
pkgs/typing/swarmauri_typing/UnionFactory.py

Copy link
Collaborator

@MichaelDecent MichaelDecent left a 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.

Copy link
Contributor

@cobycloud cobycloud left a 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.

@cobycloud
Copy link
Contributor

@VijayVignesh1 do you have any logs or screenshots of unexpected behavior that you've observed?

@VijayVignesh1
Copy link
Author

VijayVignesh1 commented Apr 11, 2025

@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!

@VijayVignesh1
Copy link
Author

@cobycloud Here is the screenshot of the error.
Screenshot 2025-04-11 at 8 36 17 AM

@VijayVignesh1
Copy link
Author

@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.
return Annotated.class_getitem((base_type, *old_metadata, new_metadata))
Let me know if this is fine. I can push the updated code.

@VijayVignesh1
Copy link
Author

@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))
Copy link
Collaborator

@MichaelDecent MichaelDecent Apr 22, 2025

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.

Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants