mirror of
https://github.com/explosion/spaCy.git
synced 2025-12-12 04:34:31 +03:00
Fix typing errors with set_extenion methods
eg:
```
Argument of type "(span: Span, tag: str) -> str" cannot be assigned to parameter "method" of type "SpanMethod | None" in function "set_extension"
Type "(span: Span, tag: str) -> str" is incompatible with type "SpanMethod | None"
"function" is incompatible with protocol "SpanMethod"
"__call__" is not present
"function" is incompatible with "None"PylancereportArgumentType
```
Rationale:
`Callable` only accepts a single parameter, optional parameters don't work
... isn't recognized as variadic arguments (... not valid here)
SomeMethod(Protocol) __call__ approach doesn't support mapping non variadic arguments to variadic arguments.
Therefore, to not break the currently documented interface, implement a union of Callable overloads.
This commit is contained in:
parent
319e02545c
commit
8a45a9fb89
|
|
@ -28,8 +28,12 @@ from .underscore import Underscore
|
||||||
|
|
||||||
DOCBIN_ALL_ATTRS: Tuple[str, ...]
|
DOCBIN_ALL_ATTRS: Tuple[str, ...]
|
||||||
|
|
||||||
class DocMethod(Protocol):
|
DocMethod = Union[
|
||||||
def __call__(self: Doc, *args: Any, **kwargs: Any) -> Any: ... # type: ignore[misc]
|
Callable[[Doc], Any],
|
||||||
|
Callable[[Doc, Any], Any],
|
||||||
|
Callable[[Doc, Any, Any], Any],
|
||||||
|
Callable[[Doc, Any, Any, Any], Any],
|
||||||
|
]
|
||||||
|
|
||||||
class Doc:
|
class Doc:
|
||||||
vocab: Vocab
|
vocab: Vocab
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,12 @@ from .doc import Doc
|
||||||
from .token import Token
|
from .token import Token
|
||||||
from .underscore import Underscore
|
from .underscore import Underscore
|
||||||
|
|
||||||
class SpanMethod(Protocol):
|
SpanMethod = Union[
|
||||||
def __call__(self: Span, *args: Any, **kwargs: Any) -> Any: ... # type: ignore[misc]
|
Callable[[Span], Any],
|
||||||
|
Callable[[Span, Any], Any],
|
||||||
|
Callable[[Span, Any, Any], Any],
|
||||||
|
Callable[[Span, Any, Any, Any], Any],
|
||||||
|
]
|
||||||
|
|
||||||
class Span:
|
class Span:
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,12 @@ from .morphanalysis import MorphAnalysis
|
||||||
from .span import Span
|
from .span import Span
|
||||||
from .underscore import Underscore
|
from .underscore import Underscore
|
||||||
|
|
||||||
class TokenMethod(Protocol):
|
TokenMethod = Union[
|
||||||
def __call__(self: Token, *args: Any, **kwargs: Any) -> Any: ... # type: ignore[misc]
|
Callable[[Token], Any],
|
||||||
|
Callable[[Token, Any], Any],
|
||||||
|
Callable[[Token, Any, Any], Any],
|
||||||
|
Callable[[Token, Any, Any, Any], Any],
|
||||||
|
]
|
||||||
|
|
||||||
class Token:
|
class Token:
|
||||||
i: int
|
i: int
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user