From 1e974de837cb2f548faaf72ad00213e61107e8d7 Mon Sep 17 00:00:00 2001 From: Sofie Van Landeghem Date: Fri, 27 Aug 2021 11:44:31 +0200 Subject: [PATCH] config is not Optional (#9024) --- spacy/language.py | 13 ++++++------- website/docs/api/language.md | 4 ++-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/spacy/language.py b/spacy/language.py index 99d55df81..08fb63d4c 100644 --- a/spacy/language.py +++ b/spacy/language.py @@ -605,7 +605,7 @@ class Language: factory_name: str, name: Optional[str] = None, *, - config: Optional[Dict[str, Any]] = SimpleFrozenDict(), + config: Dict[str, Any] = SimpleFrozenDict(), raw_config: Optional[Config] = None, validate: bool = True, ) -> Callable[[Doc], Doc]: @@ -615,8 +615,8 @@ class Language: factory_name (str): Name of component factory. name (Optional[str]): Optional name to assign to component instance. Defaults to factory name if not set. - config (Optional[Dict[str, Any]]): Config parameters to use for this - component. Will be merged with default config, if available. + config (Dict[str, Any]): Config parameters to use for this component. + Will be merged with default config, if available. raw_config (Optional[Config]): Internals: the non-interpolated config. validate (bool): Whether to validate the component config against the arguments and types expected by the factory. @@ -640,7 +640,6 @@ class Language: ) raise ValueError(err) pipe_meta = self.get_factory_meta(factory_name) - config = config or {} # This is unideal, but the alternative would mean you always need to # specify the full config settings, which is not really viable. if pipe_meta.default_config: @@ -722,7 +721,7 @@ class Language: first: Optional[bool] = None, last: Optional[bool] = None, source: Optional["Language"] = None, - config: Optional[Dict[str, Any]] = SimpleFrozenDict(), + config: Dict[str, Any] = SimpleFrozenDict(), raw_config: Optional[Config] = None, validate: bool = True, ) -> Callable[[Doc], Doc]: @@ -743,8 +742,8 @@ class Language: last (bool): If True, insert component last in the pipeline. source (Language): Optional loaded nlp object to copy the pipeline component from. - config (Optional[Dict[str, Any]]): Config parameters to use for this - component. Will be merged with default config, if available. + config (Dict[str, Any]): Config parameters to use for this component. + Will be merged with default config, if available. raw_config (Optional[Config]): Internals: the non-interpolated config. validate (bool): Whether to validate the component config against the arguments and types expected by the factory. diff --git a/website/docs/api/language.md b/website/docs/api/language.md index b09ae1aa2..0aa33b281 100644 --- a/website/docs/api/language.md +++ b/website/docs/api/language.md @@ -446,7 +446,7 @@ component, adds it to the pipeline and returns it. | `after` | Component name or index to insert component directly after. ~~Optional[Union[str, int]]~~ | | `first` | Insert component first / not first in the pipeline. ~~Optional[bool]~~ | | `last` | Insert component last / not last in the pipeline. ~~Optional[bool]~~ | -| `config` 3 | Optional config parameters to use for this component. Will be merged with the `default_config` specified by the component factory. ~~Optional[Dict[str, Any]]~~ | +| `config` 3 | Optional config parameters to use for this component. Will be merged with the `default_config` specified by the component factory. ~~Dict[str, Any]~~ | | `source` 3 | Optional source pipeline to copy component from. If a source is provided, the `factory_name` is interpreted as the name of the component in the source pipeline. Make sure that the vocab, vectors and settings of the source pipeline match the target pipeline. ~~Optional[Language]~~ | | `validate` 3 | Whether to validate the component config and arguments against the types expected by the factory. Defaults to `True`. ~~bool~~ | | **RETURNS** | The pipeline component. ~~Callable[[Doc], Doc]~~ | @@ -476,7 +476,7 @@ To create a component and add it to the pipeline, you should always use | `factory_name` | Name of the registered component factory. ~~str~~ | | `name` | Optional unique name of pipeline component instance. If not set, the factory name is used. An error is raised if the name already exists in the pipeline. ~~Optional[str]~~ | | _keyword-only_ | | -| `config` 3 | Optional config parameters to use for this component. Will be merged with the `default_config` specified by the component factory. ~~Optional[Dict[str, Any]]~~ | +| `config` 3 | Optional config parameters to use for this component. Will be merged with the `default_config` specified by the component factory. ~~Dict[str, Any]~~ | | `validate` 3 | Whether to validate the component config and arguments against the types expected by the factory. Defaults to `True`. ~~bool~~ | | **RETURNS** | The pipeline component. ~~Callable[[Doc], Doc]~~ |