From 94705c21c8a341e66aabce17619acb257cc58bd4 Mon Sep 17 00:00:00 2001 From: Ines Montani Date: Tue, 25 Aug 2020 17:13:11 +0200 Subject: [PATCH] Allow reuse on validators to prevent reload error Otherwise this will cause an error if spaCy is live reloaded, e.g. in Streamlit --- spacy/schemas.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spacy/schemas.py b/spacy/schemas.py index 069bd7c0a..0fdb1b332 100644 --- a/spacy/schemas.py +++ b/spacy/schemas.py @@ -63,7 +63,7 @@ class TokenPatternString(BaseModel): class Config: extra = "forbid" - @validator("*", pre=True, each_item=True) + @validator("*", pre=True, each_item=True, allow_reuse=True) def raise_for_none(cls, v): if v is None: raise ValueError("None / null is not allowed") @@ -84,7 +84,7 @@ class TokenPatternNumber(BaseModel): class Config: extra = "forbid" - @validator("*", pre=True, each_item=True) + @validator("*", pre=True, each_item=True, allow_reuse=True) def raise_for_none(cls, v): if v is None: raise ValueError("None / null is not allowed") @@ -145,7 +145,7 @@ class TokenPattern(BaseModel): allow_population_by_field_name = True alias_generator = lambda value: value.upper() - @validator("*", pre=True) + @validator("*", pre=True, allow_reuse=True) def raise_for_none(cls, v): if v is None: raise ValueError("None / null is not allowed") @@ -265,7 +265,7 @@ class ConfigSchema(BaseModel): pretraining: Union[ConfigSchemaPretrain, ConfigSchemaPretrainEmpty] = {} components: Dict[str, Dict[str, Any]] - @root_validator + @root_validator(allow_reuse=True) def validate_config(cls, values): """Perform additional validation for settings with dependencies.""" pt = values.get("pretraining")