bolkedebruin commented on code in PR #31565:
URL: https://github.com/apache/airflow/pull/31565#discussion_r1206445418
##########
airflow/serialization/serde.py:
##########
@@ -302,6 +308,11 @@ def _stringify(classname: str, version: int, value: T |
None) -> str:
return s
+def _is_pydantic(cls: Any) -> bool:
+ """Return True if the class is a pydantic model."""
+ return hasattr(cls, "validate") and hasattr(cls, "json") and hasattr(cls,
"dict")
Review Comment:
import timeit
def askisinstance(foo=object()):
return isinstance(foo, BaseModel)
def askhasattr(foo=object()):
return hasattr(foo, "validate") and hasattr(foo, "dict") and
hasattr(foo, "json")
#%%
timeit.timeit('testfunc()', 'from __main__ import askisinstance as testfunc')
timeit.timeit('testfunc()', 'from __main__ import askhasattr as testfunc')
# instance
0.19626916700508446
# hasattr
0.06582462496589869
--
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]