Skip to content

Commit

Permalink
Merge branch 'main' of github.com:izxxr/oblate
Browse files Browse the repository at this point in the history
  • Loading branch information
izxxr committed Feb 14, 2024
2 parents aa63e1e + c0ca9a1 commit 87638c6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
17 changes: 10 additions & 7 deletions oblate/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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]:
Expand Down
3 changes: 2 additions & 1 deletion oblate/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
'MISSING',
'current_context',
'current_field_key',
'current_schema',
)


Expand All @@ -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')
3 changes: 0 additions & 3 deletions tests/test_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 87638c6

Please sign in to comment.