skrawcz commented on code in PR #617:
URL: https://github.com/apache/burr/pull/617#discussion_r3115448172


##########
burr/core/action.py:
##########
@@ -62,6 +62,18 @@
     except ImportError:
         pass
 
+try:
+    UnionType = types.UnionType
+except AttributeError:  # py<3.10
+    UnionType = None
+
+if typing.TYPE_CHECKING:
+    StreamingPydanticType = Any
+else:
+    StreamingPydanticType = Union[Type["BaseModel"], Type[dict]]
+    if UnionType is not None:
+        StreamingPydanticType = Union[Type["BaseModel"], Type[dict], UnionType]

Review Comment:
   The `TYPE_CHECKING = Any` pattern effectively disables the type checker for 
`stream_type`. Replace with:
   ```python
   if sys.version_info >= (3, 10):
       StreamingPydanticType = Union[Type["BaseModel"], Type[dict], 
types.UnionType]
   else:
       StreamingPydanticType = Union[Type["BaseModel"], Type[dict]]
   ```
   `sys` is already imported in this file. Pyright natively narrows on 
`sys.version_info` checks.



##########
burr/integrations/pydantic.py:
##########
@@ -264,7 +265,17 @@ async def async_action_function(state: State, **kwargs) -> 
State:
     return decorator
 
 
-PartialType = Union[Type[pydantic.BaseModel], Type[dict]]
+try:
+    UnionType = types.UnionType
+except AttributeError:  # py<3.10
+    UnionType = None
+
+if typing.TYPE_CHECKING:
+    PartialType = Any
+else:
+    PartialType = Union[Type[pydantic.BaseModel], Type[dict]]
+    if UnionType is not None:
+        PartialType = Union[Type[pydantic.BaseModel], Type[dict], UnionType]

Review Comment:
   Same issue — replace the `TYPE_CHECKING = Any` pattern with the 
`sys.version_info` guard for `PartialType`.



##########
burr/integrations/pydantic.py:
##########
@@ -22,6 +22,7 @@
 import types
 import typing
 from typing import (

Review Comment:
   Nit: the `Any` import can be removed if switching to the `sys.version_info` 
approach.



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