tvalentyn commented on code in PR #27633:
URL: https://github.com/apache/beam/pull/27633#discussion_r1272486177


##########
sdks/python/apache_beam/typehints/typehints.py:
##########
@@ -355,9 +355,12 @@ def is_typing_generic(type_param):
 
   Such objects are considered valid type parameters.
 
-  Always returns false for Python versions below 3.7.
+  Always returns false for Python versions below 3.7. For versions 3.9 and
+  above, also permits types.GenericAlias.
   """
-  if hasattr(typing, '_GenericAlias'):
+  if hasattr(typing, '_GenericAlias') and hasattr(types, "GenericAlias"):
+    return isinstance(type_param, (typing._GenericAlias, types.GenericAlias))

Review Comment:
   Would this be more clear (assuming it's still correct and accurate):
   ```
     if hasattr(typing, '_GenericAlias') and isinstance(type_param, 
typing._GenericAlias):
       # Python 3.9, 3.10:
       return True
     if hasattr(types, 'GenericAlias') and isinstance(type_param, 
types.GenericAlias):
       # Python 3.11+
       return True
     return False
   ```
   



##########
sdks/python/apache_beam/typehints/native_type_compatibility_test.py:
##########
@@ -49,6 +49,11 @@ class _TestGeneric(typing.Generic[T]):
   pass
 
 
+class _TestPair(typing.NamedTuple('DataPair', [('base', T), ('diff', T)]),

Review Comment:
   please select some generic values for the stub to unnecessary association 
with domain-specific code where the snippet came from.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to