From 3c9778385dc0552201788de52eddb154bfd0319d Mon Sep 17 00:00:00 2001 From: p1c2u Date: Sun, 23 May 2021 11:37:35 +0100 Subject: [PATCH] Get rid of NoValue type --- openapi_core/casting/schemas/casters.py | 5 +-- openapi_core/types.py | 1 - .../unmarshalling/schemas/unmarshallers.py | 13 +++--- tests/unit/unmarshalling/test_unmarshal.py | 42 ------------------- 4 files changed, 7 insertions(+), 54 deletions(-) delete mode 100644 openapi_core/types.py diff --git a/openapi_core/casting/schemas/casters.py b/openapi_core/casting/schemas/casters.py index 048de19b..181d8813 100644 --- a/openapi_core/casting/schemas/casters.py +++ b/openapi_core/casting/schemas/casters.py @@ -1,7 +1,6 @@ from __future__ import division from openapi_core.casting.schemas.exceptions import CastError -from openapi_core.types import NoValue class PrimitiveCaster(object): @@ -11,7 +10,7 @@ def __init__(self, schema, caster_callable): self.caster_callable = caster_callable def __call__(self, value): - if value in (None, NoValue): + if value is None: return value try: return self.caster_callable(value) @@ -36,6 +35,6 @@ def items_caster(self): return self.casters_factory.create(self.schema / 'items') def __call__(self, value): - if value in (None, NoValue): + if value is None: return value return list(map(self.items_caster, value)) diff --git a/openapi_core/types.py b/openapi_core/types.py deleted file mode 100644 index 8a8874d5..00000000 --- a/openapi_core/types.py +++ /dev/null @@ -1 +0,0 @@ -NoValue = object() diff --git a/openapi_core/unmarshalling/schemas/unmarshallers.py b/openapi_core/unmarshalling/schemas/unmarshallers.py index 2faf6165..a0e14cb9 100644 --- a/openapi_core/unmarshalling/schemas/unmarshallers.py +++ b/openapi_core/unmarshalling/schemas/unmarshallers.py @@ -14,7 +14,6 @@ from openapi_core.schema.schemas import ( get_all_properties, get_all_properties_names ) -from openapi_core.types import NoValue from openapi_core.unmarshalling.schemas.enums import UnmarshalContext from openapi_core.unmarshalling.schemas.exceptions import ( UnmarshalError, ValidateError, InvalidSchemaValue, @@ -38,9 +37,7 @@ def __init__(self, formatter, validator, schema): self.validator = validator self.schema = schema - def __call__(self, value=NoValue): - if value is NoValue: - value = self.schema.getkey('default') + def __call__(self, value): if value is None: return @@ -145,7 +142,7 @@ class ArrayUnmarshaller(ComplexUnmarshaller): def items_unmarshaller(self): return self.unmarshallers_factory.create(self.schema / 'items') - def __call__(self, value=NoValue): + def __call__(self, value): value = super(ArrayUnmarshaller, self).__call__(value) if value is None and self.schema.getkey('nullable', False): return None @@ -172,7 +169,7 @@ def unmarshal(self, value): else: return self._unmarshal_object(value) - def _unmarshal_object(self, value=NoValue): + def _unmarshal_object(self, value): if 'oneOf' in self.schema: properties = None for one_of_schema in self.schema / 'oneOf': @@ -199,7 +196,7 @@ def _unmarshal_object(self, value=NoValue): return properties - def _unmarshal_properties(self, value=NoValue, one_of_schema=None): + def _unmarshal_properties(self, value, one_of_schema=None): all_props = get_all_properties(self.schema) all_props_names = get_all_properties_names(self.schema) @@ -255,7 +252,7 @@ class AnyUnmarshaller(ComplexUnmarshaller): 'integer', 'number', 'string', ] - def unmarshal(self, value=NoValue): + def unmarshal(self, value): one_of_schema = self._get_one_of_schema(value) if one_of_schema: return self.unmarshallers_factory.create(one_of_schema)(value) diff --git a/tests/unit/unmarshalling/test_unmarshal.py b/tests/unit/unmarshalling/test_unmarshal.py index 4b38d67f..f959de9d 100644 --- a/tests/unit/unmarshalling/test_unmarshal.py +++ b/tests/unit/unmarshalling/test_unmarshal.py @@ -5,7 +5,6 @@ import pytest from openapi_core.spec.paths import SpecPath -from openapi_core.types import NoValue from openapi_core.unmarshalling.schemas.enums import UnmarshalContext from openapi_core.unmarshalling.schemas.exceptions import ( InvalidSchemaFormatValue, InvalidSchemaValue, UnmarshalError, @@ -158,34 +157,6 @@ def test_string_float_invalid(self, unmarshaller_factory): with pytest.raises(InvalidSchemaValue): unmarshaller_factory(schema)(value) - def test_string_default(self, unmarshaller_factory): - default_value = 'default' - spec = { - 'type': 'string', - 'default': default_value, - } - schema = SpecPath.from_spec(spec) - value = NoValue - - result = unmarshaller_factory(schema)(value) - - assert result == default_value - - @pytest.mark.parametrize('default_value', ['default', None]) - def test_string_default_nullable( - self, default_value, unmarshaller_factory): - spec = { - 'type': 'string', - 'default': default_value, - 'nullable': True, - } - schema = SpecPath.from_spec(spec) - value = NoValue - - result = unmarshaller_factory(schema)(value) - - assert result == default_value - def test_string_format_date(self, unmarshaller_factory): spec = { 'type': 'string', @@ -361,19 +332,6 @@ def test_integer_enum_string_invalid(self, unmarshaller_factory): with pytest.raises(UnmarshalError): unmarshaller_factory(schema)(value) - def test_integer_default(self, unmarshaller_factory): - default_value = 123 - spec = { - 'type': 'integer', - 'default': default_value, - } - schema = SpecPath.from_spec(spec) - value = NoValue - - result = unmarshaller_factory(schema)(value) - - assert result == default_value - def test_integer_default_nullable(self, unmarshaller_factory): default_value = 123 spec = { pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy