Skip to content

Commit

Permalink
🚑 version 0.5.15
Browse files Browse the repository at this point in the history
fix GenericAlias for python >= 3.9
  • Loading branch information
RF-Tar-Railt committed Sep 26, 2023
1 parent 7c97d36 commit 1481ab5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions nepattern/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,11 @@ def type_parser(item: Any, extra: str = "allow") -> BasePattern:
if item and (pat := all_patterns().get(item, None)):
return pat
with suppress(TypeError):
if not inspect.isclass(item) and isinstance(item, (GenericAlias, CGenericAlias, CUnionType)):
if isinstance(item, (GenericAlias, CGenericAlias, CUnionType)):
return _generic_parser(item, extra)
if isinstance(item, TypeVar):
return _typevar_parser(item)
if inspect.isclass(item) and getattr(item, "_is_protocol", False):
if getattr(item, "_is_protocol", False):
return _protocol_parser(item)
if isinstance(item, (FunctionType, MethodType, LambdaType)):
if len((sig := inspect.signature(item)).parameters) not in (1, 2): # pragma: no cover
Expand Down
7 changes: 5 additions & 2 deletions nepattern/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
from pathlib import Path
from tarina.lang import lang

if sys.version_info >= (3, 10): # pragma: no cover
if sys.version_info >= (3, 9): # pragma: no cover
from types import GenericAlias as CGenericAlias # noqa
from types import UnionType as CUnionType # noqa
else:
CGenericAlias: type = type(List[int]) # noqa

if sys.version_info >= (3, 10): # pragma: no cover
from types import UnionType as CUnionType # noqa
else:
CUnionType: type = type(Union[int, str]) # noqa

if TYPE_CHECKING:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "nepattern"
version = "0.5.14"
version = "0.5.15"
description = "a complex pattern, support typing"
authors = [
{name = "RF-Tar-Railt", email = "rf_tar_railt@qq.com"},
Expand Down

0 comments on commit 1481ab5

Please sign in to comment.