From abf3e2dc8666241f2dfb768715d12250b69824a1 Mon Sep 17 00:00:00 2001 From: sung Date: Sat, 21 Jan 2023 10:03:50 -0800 Subject: [PATCH 1/2] hotfix --- python/tvm/tir/schedule/_type_checker.py | 31 ++++++++++++------------ 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/python/tvm/tir/schedule/_type_checker.py b/python/tvm/tir/schedule/_type_checker.py index 12ce1ebc1f92..c08fdea23366 100644 --- a/python/tvm/tir/schedule/_type_checker.py +++ b/python/tvm/tir/schedule/_type_checker.py @@ -26,6 +26,17 @@ def _is_none_type(type_: Any) -> bool: return type_ is None or type_ is type(None) +def get_subtypes(type_: Any): + # TODO(@tvm-team): This is hot fix to support subtle difference between python versions + # Would be nice to find a better way if possible + if hasattr(typing, "_SpecialGenericAlias"): + if hasattr(typing, "get_args"): + subtypes = typing.get_args(type_) # type: ignore + else: + subtypes = type_.__args__ + else: + subtypes = type_.__args__ + return subtypes if hasattr(typing, "_GenericAlias"): # For python versions 3.7 onward, check the __origin__ attribute. @@ -64,10 +75,7 @@ def dict_(type_: Any) -> Any: @staticmethod def tuple_(type_: Any) -> Optional[List[type]]: if _Subtype._origin(type_) is tuple: - if hasattr(typing, "get_args"): - subtypes = typing.get_args(type_) # type: ignore - else: - subtypes = type_.__args__ + subtypes = get_subtypes(type_) return subtypes return None @@ -76,10 +84,7 @@ def optional( # pylint: disable=missing-function-docstring type_: Any, ) -> Optional[List[type]]: if _Subtype._origin(type_) is Union: - if hasattr(typing, "get_args"): - subtypes = typing.get_args(type_) # type: ignore - else: - subtypes = type_.__args__ + subtypes = get_subtypes(type_) if len(subtypes) == 2 and _is_none_type(subtypes[1]): return [subtypes[0]] return None @@ -87,10 +92,7 @@ def optional( # pylint: disable=missing-function-docstring @staticmethod def union(type_: Any) -> Optional[List[type]]: # pylint: disable=missing-function-docstring if _Subtype._origin(type_) is Union: - if hasattr(typing, "get_args"): - subtypes = typing.get_args(type_) # type: ignore - else: - subtypes = type_.__args__ + subtypes = get_subtypes(type_) if len(subtypes) != 2 or not _is_none_type(subtypes[1]): return list(subtypes) return None @@ -98,10 +100,7 @@ def union(type_: Any) -> Optional[List[type]]: # pylint: disable=missing-functi @staticmethod def callable(type_: Any) -> Optional[List[type]]: if _Subtype._origin(type_) is collections.abc.Callable: - if hasattr(typing, "get_args") and not type_._special: - subtypes = typing.get_args(type_) # type: ignore - else: - subtypes = type_.__args__ + subtypes = get_subtypes(type_) return subtypes return None From e48ebd559cf834cf1868d0f6997be15556a0113c Mon Sep 17 00:00:00 2001 From: sung Date: Sun, 22 Jan 2023 01:27:38 -0800 Subject: [PATCH 2/2] fix lint --- python/tvm/tir/schedule/_type_checker.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/python/tvm/tir/schedule/_type_checker.py b/python/tvm/tir/schedule/_type_checker.py index c08fdea23366..cb2d6446b3ef 100644 --- a/python/tvm/tir/schedule/_type_checker.py +++ b/python/tvm/tir/schedule/_type_checker.py @@ -26,7 +26,8 @@ def _is_none_type(type_: Any) -> bool: return type_ is None or type_ is type(None) -def get_subtypes(type_: Any): + +def _get_subtypes(type_: Any) -> Any: # TODO(@tvm-team): This is hot fix to support subtle difference between python versions # Would be nice to find a better way if possible if hasattr(typing, "_SpecialGenericAlias"): @@ -38,6 +39,7 @@ def get_subtypes(type_: Any): subtypes = type_.__args__ return subtypes + if hasattr(typing, "_GenericAlias"): # For python versions 3.7 onward, check the __origin__ attribute. @@ -75,7 +77,7 @@ def dict_(type_: Any) -> Any: @staticmethod def tuple_(type_: Any) -> Optional[List[type]]: if _Subtype._origin(type_) is tuple: - subtypes = get_subtypes(type_) + subtypes = _get_subtypes(type_) return subtypes return None @@ -84,7 +86,7 @@ def optional( # pylint: disable=missing-function-docstring type_: Any, ) -> Optional[List[type]]: if _Subtype._origin(type_) is Union: - subtypes = get_subtypes(type_) + subtypes = _get_subtypes(type_) if len(subtypes) == 2 and _is_none_type(subtypes[1]): return [subtypes[0]] return None @@ -92,7 +94,7 @@ def optional( # pylint: disable=missing-function-docstring @staticmethod def union(type_: Any) -> Optional[List[type]]: # pylint: disable=missing-function-docstring if _Subtype._origin(type_) is Union: - subtypes = get_subtypes(type_) + subtypes = _get_subtypes(type_) if len(subtypes) != 2 or not _is_none_type(subtypes[1]): return list(subtypes) return None @@ -100,7 +102,7 @@ def union(type_: Any) -> Optional[List[type]]: # pylint: disable=missing-functi @staticmethod def callable(type_: Any) -> Optional[List[type]]: if _Subtype._origin(type_) is collections.abc.Callable: - subtypes = get_subtypes(type_) + subtypes = _get_subtypes(type_) return subtypes return None