Skip to content

Commit

Permalink
[Bugfix][TIR] Patch for PR#13269 to support Python 3.10 (#13350)
Browse files Browse the repository at this point in the history
It seems like there is some inconsistency across the python versions and make PR #13269 fails at Python 3.10. 
This patch fixes this issue. 

Co-authored-by: Junru Shao <junrushao1994@gmail.com>
  • Loading branch information
sunggg and junrushao authored Nov 11, 2022
1 parent f950b11 commit 6d68aff
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions python/tvm/tir/schedule/_type_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,24 @@
import inspect
from typing import Any, Callable, Dict, List, Optional, Tuple, TypeVar, Union
import typing
import sys


def _is_none_type(type_: Any) -> bool:
return type_ is None or type_ is type(None)


def get_python_version():
return sys.version_info[:3]


if hasattr(typing, "_GenericAlias"):
# For python versions 3.7 onward, check the __origin__ attribute.

class _Subtype:
@staticmethod
def _origin(type_: Any) -> Any:
if get_python_version() >= (3, 9, 0):
if hasattr(typing, "_SpecialGenericAlias"):
if isinstance(type_, typing._SpecialGenericAlias): # type: ignore # pylint: disable=protected-access
return type_.__origin__
else:
if isinstance(type_, typing._GenericAlias): # type: ignore # pylint: disable=protected-access
return type_.__origin__

if isinstance(type_, typing._GenericAlias): # type: ignore # pylint: disable=protected-access
return type_.__origin__
return None

@staticmethod
Expand Down

0 comments on commit 6d68aff

Please sign in to comment.