From 228045464b15de57483926228cb5d045b75998b9 Mon Sep 17 00:00:00 2001 From: Mike Ribbons Date: Tue, 10 Sep 2024 21:15:44 +1000 Subject: [PATCH] change set_extension method argument to Callable[] --- spacy/tokens/doc.pyi | 13 +++---------- spacy/tokens/span.pyi | 13 +++---------- spacy/tokens/token.pyi | 13 +++---------- 3 files changed, 9 insertions(+), 30 deletions(-) diff --git a/spacy/tokens/doc.pyi b/spacy/tokens/doc.pyi index 62a20279c..c34f7650c 100644 --- a/spacy/tokens/doc.pyi +++ b/spacy/tokens/doc.pyi @@ -28,13 +28,6 @@ from .underscore import Underscore DOCBIN_ALL_ATTRS: Tuple[str, ...] -DocMethod = Union[ - Callable[[Doc], Any], - Callable[[Doc, Any], Any], - Callable[[Doc, Any, Any], Any], - Callable[[Doc, Any, Any, Any], Any], -] - class Doc: vocab: Vocab mem: Pool @@ -57,7 +50,7 @@ class Doc: default: Optional[Any] = ..., getter: Optional[Callable[[Doc], Any]] = ..., setter: Optional[Callable[[Doc, Any], None]] = ..., - method: Optional[DocMethod] = ..., + method: Optional[Callable[[Doc, Any]]] = ..., force: bool = ..., ) -> None: ... @classmethod @@ -65,7 +58,7 @@ class Doc: cls, name: str ) -> Tuple[ Optional[Any], - Optional[DocMethod], + Optional[Callable[[Doc, Any]]], Optional[Callable[[Doc], Any]], Optional[Callable[[Doc, Any], None]], ]: ... @@ -76,7 +69,7 @@ class Doc: cls, name: str ) -> Tuple[ Optional[Any], - Optional[DocMethod], + Optional[Callable[[Doc, Any]]], Optional[Callable[[Doc], Any]], Optional[Callable[[Doc, Any], None]], ]: ... diff --git a/spacy/tokens/span.pyi b/spacy/tokens/span.pyi index 1714f732d..91ede582a 100644 --- a/spacy/tokens/span.pyi +++ b/spacy/tokens/span.pyi @@ -8,13 +8,6 @@ from .doc import Doc from .token import Token from .underscore import Underscore -SpanMethod = Union[ - Callable[[Span], Any], - Callable[[Span, Any], Any], - Callable[[Span, Any, Any], Any], - Callable[[Span, Any, Any, Any], Any], -] - class Span: @classmethod def set_extension( @@ -23,7 +16,7 @@ class Span: default: Optional[Any] = ..., getter: Optional[Callable[[Span], Any]] = ..., setter: Optional[Callable[[Span, Any], None]] = ..., - method: Optional[SpanMethod] = ..., + method: Optional[Callable[[Span, Any]]] = ..., force: bool = ..., ) -> None: ... @classmethod @@ -31,7 +24,7 @@ class Span: cls, name: str ) -> Tuple[ Optional[Any], - Optional[SpanMethod], + Optional[Callable[[Span, Any]]], Optional[Callable[[Span], Any]], Optional[Callable[[Span, Any], None]], ]: ... @@ -42,7 +35,7 @@ class Span: cls, name: str ) -> Tuple[ Optional[Any], - Optional[SpanMethod], + Optional[Callable[[Span, Any]]], Optional[Callable[[Span], Any]], Optional[Callable[[Span, Any], None]], ]: ... diff --git a/spacy/tokens/token.pyi b/spacy/tokens/token.pyi index 4bc41d517..9e47a1b20 100644 --- a/spacy/tokens/token.pyi +++ b/spacy/tokens/token.pyi @@ -9,13 +9,6 @@ from .morphanalysis import MorphAnalysis from .span import Span from .underscore import Underscore -TokenMethod = Union[ - Callable[[Token], Any], - Callable[[Token, Any], Any], - Callable[[Token, Any, Any], Any], - Callable[[Token, Any, Any, Any], Any], -] - class Token: i: int doc: Doc @@ -27,7 +20,7 @@ class Token: default: Optional[Any] = ..., getter: Optional[Callable[[Token], Any]] = ..., setter: Optional[Callable[[Token, Any], None]] = ..., - method: Optional[TokenMethod] = ..., + method: Optional[Callable[[Token, Any]]] = ..., force: bool = ..., ) -> None: ... @classmethod @@ -35,7 +28,7 @@ class Token: cls, name: str ) -> Tuple[ Optional[Any], - Optional[TokenMethod], + Optional[Callable[[Token, Any]]], Optional[Callable[[Token], Any]], Optional[Callable[[Token, Any], None]], ]: ... @@ -46,7 +39,7 @@ class Token: cls, name: str ) -> Tuple[ Optional[Any], - Optional[TokenMethod], + Optional[Callable[[Token, Any]]], Optional[Callable[[Token], Any]], Optional[Callable[[Token, Any], None]], ]: ...