Skip to content

Commit

Permalink
Type aliases supported.
Browse files Browse the repository at this point in the history
Refs #121.
  • Loading branch information
coady committed Jun 8, 2024
1 parent 2372ea6 commit 9a12e0e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
### Changed
* `multidispatch` supports variable keyword arguments
* `multidispatch` base implementation always matches
* Type aliases supported

## [1.11.2](https://pypi.org/project/multimethod/1.11.2/) - 2024-02-27
### Fixed
Expand Down
2 changes: 2 additions & 0 deletions multimethod/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ def __new__(cls, tp, *args):
return object
if hasattr(tp, '__supertype__'): # isinstance(..., NewType) only supported >=3.10
tp = tp.__supertype__
if hasattr(typing, 'TypeAliasType') and isinstance(tp, typing.TypeAliasType):
tp = tp.__value__
if isinstance(tp, TypeVar):
if not tp.__constraints__:
return object
Expand Down
6 changes: 6 additions & 0 deletions tests/test_subscripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ def test_union():
assert issubclass(subtype(int | float), subtype(int | float | None))


@pytest.mark.skipif(sys.version_info < (3, 12), reason="Type aliases added in 3.12")
def test_type_alias():
Point = typing.TypeAliasType(name='Point', value=tuple[int, int])
assert isinstance((0, 0), subtype(Point))


def test_type():
@multimethod
def func(arg: Type[int]):
Expand Down

0 comments on commit 9a12e0e

Please sign in to comment.