diff --git a/plum/dispatcher.py b/plum/dispatcher.py index bf018c39..0f2b5adc 100644 --- a/plum/dispatcher.py +++ b/plum/dispatcher.py @@ -1,4 +1,4 @@ -from typing import Any, Callable, Dict, Optional, Tuple, TypeVar, Union +from typing import Any, Dict, Optional, Tuple, TypeVar, Union from .function import Function from .overload import get_overloads diff --git a/plum/function.py b/plum/function.py index 15b4b9c6..fd53c65a 100644 --- a/plum/function.py +++ b/plum/function.py @@ -3,6 +3,7 @@ from functools import wraps from types import MethodType from typing import Any, Callable, List, Optional, Tuple, TypeVar, Union +from copy import copy from .resolver import AmbiguousLookupError, NotFoundLookupError, Resolver from .signature import Signature, append_default_args, extract_signature @@ -281,7 +282,7 @@ def _resolve_pending_registrations(self) -> None: else: # Ensure that the implementation is `f`, but make a copy before # mutating. - signature = signature.__copy__() + signature = copy(signature) signature.implementation = f # Ensure that the implementation has the right name, because this name diff --git a/plum/promotion.py b/plum/promotion.py index c34f8ae3..344f67dc 100644 --- a/plum/promotion.py +++ b/plum/promotion.py @@ -126,7 +126,7 @@ def rule(t1: type1, t2: type2): # If the types are the same, the method will get overwritten. @_promotion_rule.dispatch - def rule(t1: type2, t2: type1): + def rule(t1: type2, t2: type1): # noqa F811 return type_to @@ -161,11 +161,11 @@ def _promote_types(t0, t1): @_dispatch -def promote(obj: object): +def promote(obj: object): # noqa F811 # Promote should always return a tuple to avoid edge cases. return (obj,) @_dispatch -def promote(): +def promote(): # noqa F811 return () diff --git a/plum/signature.py b/plum/signature.py index 0f6c97df..5486725a 100644 --- a/plum/signature.py +++ b/plum/signature.py @@ -1,7 +1,9 @@ +from typing import Callable, List, Tuple, Optional + +import typing import inspect import operator -import typing -from typing import Callable, List, Optional, Tuple +from copy import copy import beartype.door from beartype.peps import resolve_pep563 @@ -286,15 +288,15 @@ def append_default_args(signature: Signature, f: Callable) -> List[Signature]: if p.kind == p.VAR_POSITIONAL: continue - copy = signatures[-1].__copy__() + signature_copy = copy(signatures[-1]) # As specified over, these additional signatures should never have variable # arguments. - copy.varargs = Missing + signature_copy.varargs = Missing # Remove the last positional argument. - copy.types = copy.types[:-1] + signature_copy.types = signature_copy.types[:-1] - signatures.append(copy) + signatures.append(signature_copy) return signatures diff --git a/plum/util.py b/plum/util.py index fbce29cf..4c9629a6 100644 --- a/plum/util.py +++ b/plum/util.py @@ -1,7 +1,7 @@ import abc import sys import typing -from typing import Callable, List +from typing import List if sys.version_info.minor <= 8: # pragma: specific no cover 3.9 3.10 3.11 from typing import Callable