Skip to content

Commit bf91948

Browse files
williamwen42meta-codesync[bot]
authored andcommitted
fix tracing typing.Union (#164004)
Summary: X-link: pytorch/pytorch#164004 Approved by: https://github.com/anijain2305, https://github.com/mlazos ghstack dependencies: #161838, #161555, #161839, #163009, #163109, #163110, #163191, #163292, #163796, #163818, #163919, #163920 Reviewed By: yangw-dev Differential Revision: D83589243 fbshipit-source-id: b4d5495ef14b3de556268131d40f69157cc167d8
1 parent ceb79e1 commit bf91948

File tree

1 file changed

+8
-2
lines changed
  • userbenchmark/dynamo/dynamobench/_dynamo

1 file changed

+8
-2
lines changed

userbenchmark/dynamo/dynamobench/_dynamo/utils.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,8 @@ def istype(obj: object, allowed_types: Any) -> bool:
10251025
if sys.version_info >= (3, 12):
10261026
# Some typing classes moved to C in 3.12,
10271027
# which no longer have the _Final mixin.
1028+
# Check for consistency e.g. here:
1029+
# https://github.com/python/cpython/blob/f2b82b3b3b1f8c7a81e84df35ee921e44517cf32/Lib/typing.py#L32
10281030
_builtin_final_typing_classes = (
10291031
typing.ParamSpecArgs,
10301032
typing.ParamSpecKwargs,
@@ -1039,14 +1041,18 @@ def is_typing(value: Any) -> bool:
10391041
# _Final catches most of typing classes:
10401042
# - Any
10411043
# - Callable
1042-
# - Union
1044+
# - Union (Python < 3.14)
10431045
# ...
10441046
#
10451047
# NB: we intentionally ignore classes that inherit from Generic, since they
10461048
# can be used as both TypingVariable as well as UserDefinedClassVariable.
10471049
if sys.version_info >= (3, 12) and isinstance(value, _builtin_final_typing_classes):
10481050
return True
1049-
return isinstance(value, typing._Final) or value is typing.Generic # type: ignore[attr-defined]
1051+
return (
1052+
isinstance(value, typing._Final) # type: ignore[attr-defined]
1053+
or value is typing.Generic
1054+
or value is typing.Union
1055+
)
10501056

10511057

10521058
def is_numpy_int_type(value: Any) -> bool:

0 commit comments

Comments
 (0)