3
3
from copy import copy
4
4
from functools import wraps
5
5
from types import MethodType
6
- from typing import Any , Callable , List , Optional , Protocol , Tuple , TypeVar , Union
6
+ from typing import Any , Callable , Optional , Protocol , TypeVar , Union
7
7
8
8
from .method import Method
9
9
from .resolver import AmbiguousLookupError , NotFoundLookupError , Resolver
20
20
# `typing.Self` is available for Python 3.11 and higher.
21
21
try : # pragma: specific no cover 3.11
22
22
from typing import Self
23
- except ImportError : # pragma: specific no cover 3.8 3.9 3. 10
23
+ except ImportError : # pragma: specific no cover 3.10
24
24
Self = TypeVar ("Self" , bound = "Function" )
25
25
26
26
SomeExceptionType = TypeVar ("SomeExceptionType" , bound = Exception )
@@ -96,12 +96,12 @@ def __init__(
96
96
self ._warn_redefinition = warn_redefinition
97
97
98
98
# Initialise pending and resolved methods.
99
- self ._pending : List [ Tuple [Callable , Optional [Signature ], int ]] = []
99
+ self ._pending : list [ tuple [Callable , Optional [Signature ], int ]] = []
100
100
self ._resolver = Resolver (
101
101
self .__name__ ,
102
102
warn_redefinition = self ._warn_redefinition ,
103
103
)
104
- self ._resolved : List [ Tuple [Callable , Signature , int ]] = []
104
+ self ._resolved : list [ tuple [Callable , Signature , int ]] = []
105
105
106
106
@property
107
107
def owner (self ):
@@ -125,7 +125,7 @@ def __doc__(self) -> Optional[str]:
125
125
"""
126
126
try :
127
127
self ._resolve_pending_registrations ()
128
- except NameError : # pragma: specific no cover 3.7 3.8 3. 9
128
+ except NameError : # pragma: specific no cover 3.9
129
129
# When `staticmethod` is combined with
130
130
# `from __future__ import annotations`, in Python 3.10 and higher
131
131
# `staticmethod` will attempt to inherit `__doc__` (see
@@ -176,7 +176,7 @@ def __doc__(self, value: str) -> None:
176
176
self ._doc = value if value else ""
177
177
178
178
@property
179
- def methods (self ) -> List [Signature ]:
179
+ def methods (self ) -> list [Signature ]:
180
180
"""list[:class:`.signature.Signature`]: All available methods."""
181
181
self ._resolve_pending_registrations ()
182
182
return self ._resolver .methods
@@ -199,7 +199,7 @@ def dispatch(
199
199
return self
200
200
201
201
def dispatch_multi (
202
- self : Self , * signatures : Union [Signature , Tuple [TypeHint , ...]]
202
+ self : Self , * signatures : Union [Signature , tuple [TypeHint , ...]]
203
203
) -> Callable [[Callable ], Self ]:
204
204
"""Decorator to extend the function with multiple signatures at once.
205
205
@@ -296,8 +296,8 @@ def _resolve_pending_registrations(self) -> None:
296
296
self .clear_cache (reregister = False )
297
297
298
298
def resolve_method (
299
- self , target : Union [Tuple [object , ...], Signature ]
300
- ) -> Tuple [Callable , TypeHint ]:
299
+ self , target : Union [tuple [object , ...], Signature ]
300
+ ) -> tuple [Callable , TypeHint ]:
301
301
"""Find the method and return type for arguments.
302
302
303
303
Args:
@@ -336,7 +336,7 @@ def resolve_method(
336
336
337
337
def _handle_not_found_lookup_error (
338
338
self , ex : NotFoundLookupError
339
- ) -> Tuple [Callable , TypeHint ]:
339
+ ) -> tuple [Callable , TypeHint ]:
340
340
if not self .owner :
341
341
# Not in a class. Nothing we can do.
342
342
raise ex from None
@@ -384,9 +384,9 @@ def __call__(self, *args, **kw_args):
384
384
385
385
def _resolve_method_with_cache (
386
386
self ,
387
- args : Union [Tuple [object , ...], Signature , None ] = None ,
388
- types : Optional [Tuple [TypeHint , ...]] = None ,
389
- ) -> Tuple [Callable , TypeHint ]:
387
+ args : Union [tuple [object , ...], Signature , None ] = None ,
388
+ types : Optional [tuple [TypeHint , ...]] = None ,
389
+ ) -> tuple [Callable , TypeHint ]:
390
390
if args is None and types is None :
391
391
raise ValueError (
392
392
"Arguments `args` and `types` cannot both be `None`. "
@@ -525,7 +525,7 @@ def wrapped_method(*args, **kw_args):
525
525
return wrapped_method
526
526
527
527
@property
528
- def methods (self ) -> List [Signature ]:
528
+ def methods (self ) -> list [Signature ]:
529
529
"""list[:class:`.signature.Signature`]: All available methods."""
530
530
return self ._f .methods
531
531
0 commit comments