mirror of
https://github.com/explosion/spaCy.git
synced 2025-01-12 10:16:27 +03:00
fix: InitializableComponent
type hints (#12692)
* fix: InitializableComponent type hints * fix: avoid circular dependency * style: clean imports in language.py * style: use relative imports Co-authored-by: Adriane Boyd <adrianeboyd@gmail.com> * fix: apply black --------- Co-authored-by: Adriane Boyd <adrianeboyd@gmail.com>
This commit is contained in:
parent
c4112a1da3
commit
c3c064ace4
|
@ -1,6 +1,6 @@
|
||||||
from typing import Iterator, Optional, Any, Dict, Callable, Iterable
|
from typing import Iterator, Optional, Any, Dict, Callable, Iterable
|
||||||
from typing import Union, Tuple, List, Set, Pattern, Sequence
|
from typing import Union, Tuple, List, Set, Pattern, Sequence
|
||||||
from typing import NoReturn, TYPE_CHECKING, TypeVar, cast, overload
|
from typing import NoReturn, TypeVar, cast, overload
|
||||||
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
import random
|
import random
|
||||||
|
@ -1269,7 +1269,10 @@ class Language:
|
||||||
"No 'get_examples' callback provided to 'Language.initialize', creating dummy examples"
|
"No 'get_examples' callback provided to 'Language.initialize', creating dummy examples"
|
||||||
)
|
)
|
||||||
doc = Doc(self.vocab, words=["x", "y", "z"])
|
doc = Doc(self.vocab, words=["x", "y", "z"])
|
||||||
get_examples = lambda: [Example.from_dict(doc, {})]
|
|
||||||
|
def get_examples():
|
||||||
|
return [Example.from_dict(doc, {})]
|
||||||
|
|
||||||
if not hasattr(get_examples, "__call__"):
|
if not hasattr(get_examples, "__call__"):
|
||||||
err = Errors.E930.format(
|
err = Errors.E930.format(
|
||||||
method="Language.initialize", obj=type(get_examples)
|
method="Language.initialize", obj=type(get_examples)
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
from typing import Optional, Any, Iterable, Dict, Callable, Sequence, List
|
from typing import Optional, Any, Iterable, Dict, Callable, Sequence, List
|
||||||
|
|
||||||
from .compat import Protocol, runtime_checkable
|
from .compat import Protocol, runtime_checkable
|
||||||
|
|
||||||
from thinc.api import Optimizer, Model
|
from thinc.api import Optimizer, Model
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from .training import Example
|
from .training import Example
|
||||||
|
from .language import Language
|
||||||
|
|
||||||
|
|
||||||
@runtime_checkable
|
@runtime_checkable
|
||||||
|
@ -32,7 +34,7 @@ class InitializableComponent(Protocol):
|
||||||
def initialize(
|
def initialize(
|
||||||
self,
|
self,
|
||||||
get_examples: Callable[[], Iterable["Example"]],
|
get_examples: Callable[[], Iterable["Example"]],
|
||||||
nlp: Iterable["Example"],
|
nlp: "Language",
|
||||||
**kwargs: Any
|
**kwargs: Any
|
||||||
):
|
):
|
||||||
...
|
...
|
||||||
|
|
Loading…
Reference in New Issue
Block a user