diff --git a/oblate/configs.py b/oblate/configs.py index 569b326..29e7455 100644 --- a/oblate/configs.py +++ b/oblate/configs.py @@ -67,7 +67,7 @@ def __get__(self, instance: Optional[GlobalConfig], owner: Type[GlobalConfig]) - return self._default try: return instance._values[self._name] - except KeyError: + except KeyError: # pragma: no cover return self._default def __set__(self, instance: GlobalConfig, value: _T) -> None: @@ -97,14 +97,17 @@ class GlobalConfig: 'validation_error_cls', ) - def __init__(self, **options: Any) -> None: - self._values: Dict[str, Any] = {} + def __init__( + self, + *, + warn_unsupported_types: bool = True, + validation_error_cls: Type[ValidationError] = ValidationError, + ) -> None: - for name, value in options.items(): - if not name in self.__config_options__: - raise TypeError(f'Invalid config {name!r} in GlobalConfig()') + self._values: Dict[str, Any] = {} - self._values[name] = value + self.warn_unsupported_types = warn_unsupported_types + self.validation_error_cls = validation_error_cls @cfg_option def validation_error_cls(self) -> Type[ValidationError]: diff --git a/oblate/utils.py b/oblate/utils.py index ffe71a1..d98ef03 100644 --- a/oblate/utils.py +++ b/oblate/utils.py @@ -34,6 +34,7 @@ 'MISSING', 'current_context', 'current_field_key', + 'current_schema', ) @@ -55,6 +56,6 @@ def __bool__(self) -> bool: ### Context variables ### -current_context: ContextVar[_BaseValueContext] = ContextVar('_current_context') +current_context: ContextVar[_BaseValueContext] = ContextVar('current_context') current_field_key: ContextVar[str] = ContextVar('current_field_key') current_schema: ContextVar[Schema] = ContextVar('current_schema') diff --git a/tests/test_configs.py b/tests/test_configs.py index 0a548fe..d1f73d8 100644 --- a/tests/test_configs.py +++ b/tests/test_configs.py @@ -41,9 +41,6 @@ class CustomValidationError(oblate.ValidationError): ... oblate.config = oblate.GlobalConfig(validation_error_cls=CustomValidationError) assert oblate.config.validation_error_cls == CustomValidationError - with pytest.raises(TypeError, match='Invalid config'): - oblate.GlobalConfig(invalid_cfg=None) - oblate.config = oblate.GlobalConfig() assert oblate.config.validation_error_cls == oblate.ValidationError