Skip to content

Commit

Permalink
Python >=3.10 required.
Browse files Browse the repository at this point in the history
  • Loading branch information
coady committed Jan 6, 2025
1 parent 5a9b962 commit 50d8ff8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13', '3.14.0-alpha - 3.14']
python-version: ['3.10', '3.11', '3.12', '3.13', '3.14.0-alpha - 3.14']
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

## Unreleased
### Changed
* Python >=3.10 required

## [2.0](https://pypi.org/project/multimethod/2.0/) - 2024-12-26
### Removed
Expand Down
19 changes: 9 additions & 10 deletions multimethod/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import types
import typing
from collections.abc import Callable, Iterable, Iterator, Mapping
from typing import Any, Literal, Optional, TypeVar, Union, get_type_hints, overload
from typing import Any, Literal, TypeVar, Union, get_type_hints, overload


class DispatchError(TypeError):
Expand Down Expand Up @@ -57,15 +57,14 @@ def __new__(cls, tp, *args):
if isinstance(tp, typing._AnnotatedAlias):
return cls(tp.__origin__, *args)
origin = get_origin(tp) or tp
if hasattr(types, 'UnionType') and isinstance(tp, types.UnionType):
origin = Union # `|` syntax added in 3.10
args = tuple(map(cls, get_args(tp) or args))
if set(args) <= {object} and not (origin is tuple and args):
return origin
bases = (origin,) if type(origin) in (type, abc.ABCMeta) else ()
if origin is Literal:
bases = (cls(Union[tuple(map(type, args))]),)
if origin is Union:
if origin is Union or isinstance(tp, types.UnionType):
origin = types.UnionType
bases = common_bases(*args)[:1]
if bases[0] in args:
return bases[0]
Expand All @@ -90,11 +89,11 @@ def __subclasscheck__(self, subclass):
args = get_args(subclass)
if origin is Literal:
return all(isinstance(arg, self) for arg in args)
if origin is Union:
if origin in (Union, types.UnionType):
return all(issubclass(cls, self) for cls in args)
if self.__origin__ is Literal:
return False
if self.__origin__ is Union:
if self.__origin__ is types.UnionType:
return issubclass(subclass, self.__args__)
if self.__origin__ is Callable:
return (
Expand All @@ -111,7 +110,7 @@ def __subclasscheck__(self, subclass):
def __instancecheck__(self, instance):
if self.__origin__ is Literal:
return any(type(arg) is type(instance) and arg == instance for arg in self.__args__)
if self.__origin__ is Union:
if self.__origin__ is types.UnionType:
return isinstance(instance, self.__args__)
if hasattr(instance, '__orig_class__'): # user-defined generic type
return issubclass(instance.__orig_class__, self)
Expand Down Expand Up @@ -139,7 +138,7 @@ def origins(self) -> Iterable[type]:
origin = get_origin(self)
if origin is Literal:
yield from set(map(type, self.__args__))
elif origin is Union:
elif origin is types.UnionType:
for arg in self.__args__:
yield from subtype.origins(arg)
elif origin is not None:
Expand Down Expand Up @@ -192,10 +191,10 @@ class signature(tuple):
parents: set
sig: inspect.Signature

def __new__(cls, types: Iterable, required: Optional[int] = None):
def __new__(cls, types: Iterable, required: int | None = None):
return tuple.__new__(cls, map(subtype, types))

def __init__(self, types: Iterable, required: Optional[int] = None):
def __init__(self, types: Iterable, required: int | None = None):
self.required = len(self) if required is None else required

@classmethod
Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "multimethod"
version = "2.0"
description = "Multiple argument dispatching."
readme = "README.md"
requires-python = ">=3.9"
requires-python = ">=3.10"
license = {file = "LICENSE.txt"}
authors = [{name = "Aric Coady", email = "[email protected]"}]
keywords = ["multiple", "dispatch", "multidispatch", "generic", "functions", "methods", "overload"]
Expand All @@ -13,7 +13,6 @@ classifiers = [
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
Expand Down

0 comments on commit 50d8ff8

Please sign in to comment.