Skip to content

Commit c9b2d8c

Browse files
committed
attr errors hashable fix
1 parent 78ede74 commit c9b2d8c

File tree

15 files changed

+50
-46
lines changed

15 files changed

+50
-46
lines changed

openapi_core/schema/content/exceptions.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
from openapi_core.schema.exceptions import OpenAPIMappingError
2-
31
import attr
42

3+
from openapi_core.schema.exceptions import OpenAPIMappingError
4+
55

66
class OpenAPIContentError(OpenAPIMappingError):
77
pass
88

99

10-
@attr.s
10+
@attr.s(hash=True)
1111
class MimeTypeNotFound(OpenAPIContentError):
1212
mimetype = attr.ib()
1313
availableMimetypes = attr.ib()

openapi_core/schema/content/models.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ def __getitem__(self, mimetype):
1818
if fnmatch.fnmatch(mimetype, key):
1919
return value
2020

21-
raise MimeTypeNotFound(mimetype, self.keys())
21+
raise MimeTypeNotFound(mimetype, list(self.keys()))

openapi_core/schema/media_types/exceptions.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
from openapi_core.schema.exceptions import OpenAPIMappingError
2-
31
import attr
42

3+
from openapi_core.schema.exceptions import OpenAPIMappingError
4+
55

66
class OpenAPIMediaTypeError(OpenAPIMappingError):
77
pass
88

9-
@attr.s
9+
10+
@attr.s(hash=True)
1011
class InvalidMediaTypeValue(OpenAPIMediaTypeError):
1112
original_exception = attr.ib()
1213

1314
def __str__(self):
1415
return "Mimetype invalid: {0}".format(self.original_exception)
1516

16-
@attr.s
17+
18+
@attr.s(hash=True)
1719
class InvalidContentType(OpenAPIMediaTypeError):
1820
mimetype = attr.ib()
1921

openapi_core/schema/operations/exceptions.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
from openapi_core.schema.exceptions import OpenAPIMappingError
2-
31
import attr
42

3+
from openapi_core.schema.exceptions import OpenAPIMappingError
4+
55

66
class OpenAPIOperationError(OpenAPIMappingError):
77
pass
88

99

10-
@attr.s
10+
@attr.s(hash=True)
1111
class InvalidOperation(OpenAPIOperationError):
1212
path_pattern = attr.ib()
1313
http_method = attr.ib()

openapi_core/schema/parameters/exceptions.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
1-
from openapi_core.schema.exceptions import OpenAPIMappingError
2-
31
import attr
42

3+
from openapi_core.schema.exceptions import OpenAPIMappingError
4+
55

66
class OpenAPIParameterError(OpenAPIMappingError):
77
pass
88

99

10-
@attr.s
10+
@attr.s(hash=True)
1111
class MissingParameter(OpenAPIParameterError):
1212
name = attr.ib()
1313

1414
def __str__(self):
1515
return "Missing parameter (without default value): {0}".format(self.name)
1616

1717

18-
@attr.s
18+
@attr.s(hash=True)
1919
class MissingRequiredParameter(OpenAPIParameterError):
2020
name = attr.ib()
2121

2222
def __str__(self):
2323
return "Missing required parameter: {0}".format(self.name)
2424

2525

26-
@attr.s
26+
@attr.s(hash=True)
2727
class EmptyParameterValue(OpenAPIParameterError):
2828
name = attr.ib()
2929

3030
def __str__(self):
3131
return "Value of parameter cannot be empty: {0}".format(self.name)
3232

3333

34-
@attr.s
34+
@attr.s(hash=True)
3535
class InvalidParameterValue(OpenAPIParameterError):
3636
name = attr.ib()
3737
original_exception = attr.ib()

openapi_core/schema/request_bodies/exceptions.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
from openapi_core.schema.exceptions import OpenAPIMappingError
2-
31
import attr
42

3+
from openapi_core.schema.exceptions import OpenAPIMappingError
4+
55

66
class OpenAPIRequestBodyError(OpenAPIMappingError):
77
pass
88

99

10-
@attr.s
10+
@attr.s(hash=True)
1111
class MissingRequestBody(OpenAPIRequestBodyError):
1212
request = attr.ib()
1313

openapi_core/schema/responses/exceptions.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
from openapi_core.schema.exceptions import OpenAPIMappingError
2-
31
import attr
42

3+
from openapi_core.schema.exceptions import OpenAPIMappingError
4+
55

66
class OpenAPIResponseError(OpenAPIMappingError):
77
pass
88

99

10-
@attr.s
10+
@attr.s(hash=True)
1111
class InvalidResponse(OpenAPIResponseError):
1212
http_status = attr.ib()
1313
responses = attr.ib()
@@ -16,7 +16,7 @@ def __str__(self):
1616
return "Unknown response http status: {0}".format(str(self.http_status))
1717

1818

19-
@attr.s
19+
@attr.s(hash=True)
2020
class MissingResponseContent(OpenAPIResponseError):
2121
response = attr.ib()
2222

openapi_core/schema/schemas/exceptions.py

+15-13
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
from openapi_core.schema.exceptions import OpenAPIMappingError
2-
31
import attr
42

3+
from openapi_core.schema.exceptions import OpenAPIMappingError
4+
55

66
class OpenAPISchemaError(OpenAPIMappingError):
77
pass
88

99

10-
@attr.s
10+
@attr.s(hash=True)
1111
class NoValidSchema(OpenAPISchemaError):
1212
value = attr.ib()
1313

1414
def __str__(self):
1515
return "No valid schema found for value: {0}".format(self.value)
1616

1717

18-
@attr.s
18+
@attr.s(hash=True)
1919
class UndefinedItemsSchema(OpenAPISchemaError):
2020
type = attr.ib()
2121

2222
def __str__(self):
2323
return "Null value for schema type {0}".format(self.type)
2424

2525

26-
@attr.s
26+
@attr.s(hash=True)
2727
class InvalidSchemaValue(OpenAPISchemaError):
2828
msg = attr.ib()
2929
value = attr.ib()
@@ -32,58 +32,60 @@ class InvalidSchemaValue(OpenAPISchemaError):
3232
def __str__(self):
3333
return self.msg.format(value=self.value, type=self.type)
3434

35-
@attr.s
35+
36+
@attr.s(hash=True)
3637
class InvalidCustomFormatSchemaValue(InvalidSchemaValue):
3738
original_exception = attr.ib()
3839

3940
def __str__(self):
4041
return self.msg.format(value=self.value, type=self.type, exception=self.original_exception)
4142

4243

43-
@attr.s
44+
@attr.s(hash=True)
4445
class UndefinedSchemaProperty(OpenAPISchemaError):
4546
extra_props = attr.ib()
4647

4748
def __str__(self):
4849
return "Extra unexpected properties found in schema: {0}".format(self.extra_props)
4950

50-
@attr.s
51+
52+
@attr.s(hash=True)
5153
class InvalidSchemaProperty(OpenAPISchemaError):
5254
property_name = attr.ib()
5355
original_exception = attr.ib()
5456

5557
def __str__(self):
5658
return "Invalid schema property {0}: {1}".format(self.property_name, self.original_exception)
5759

58-
@attr.s
60+
61+
@attr.s(hash=True)
5962
class MissingSchemaProperty(OpenAPISchemaError):
6063
property_name = attr.ib()
6164

6265
def __str__(self):
6366
return "Missing schema property: {0}".format(self.property_name)
6467

6568

66-
@attr.s
69+
@attr.s(hash=True)
6770
class NoOneOfSchema(OpenAPISchemaError):
6871
type = attr.ib()
6972

7073
def __str__(self):
7174
return "Exactly one valid schema type {0} should be valid, None found.".format(self.type)
7275

7376

74-
@attr.s
77+
@attr.s(hash=True)
7578
class MultipleOneOfSchema(OpenAPISchemaError):
7679
type = attr.ib()
7780

7881
def __str__(self):
7982
return "Exactly one schema type {0} should be valid, more than one found".format(self.type)
8083

8184

82-
class UnmarshallerError(Exception):
85+
class UnmarshallerError(OpenAPIMappingError):
8386
pass
8487

8588

86-
@attr.s
8789
class UnmarshallerStrictTypeError(UnmarshallerError):
8890
value = attr.ib()
8991
types = attr.ib()

openapi_core/schema/servers/exceptions.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
from openapi_core.schema.exceptions import OpenAPIMappingError
2-
31
import attr
42

3+
from openapi_core.schema.exceptions import OpenAPIMappingError
4+
55

66
class OpenAPIServerError(OpenAPIMappingError):
77
pass
88

99

10-
@attr.s
10+
@attr.s(hash=True)
1111
class InvalidServer(OpenAPIServerError):
1212
full_url_pattern = attr.ib()
1313

tests/unit/schema/test_links.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@ def link_factory(request_body, server):
4040
@pytest.mark.parametrize("request_body", request_body_list)
4141
def test_iteritems(self, link_factory, request_body, server):
4242
link = link_factory(request_body, server)
43-
for par_name in link.parameters.keys():
43+
for par_name in link.parameters:
4444
assert link[par_name] == link.parameters[par_name]

tests/unit/schema/test_operations.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def operation(self):
1515
return Operation('get', '/path', {}, parameters=parameters)
1616

1717
def test_iteritems(self, operation):
18-
for name in operation.parameters.keys():
18+
for name in operation.parameters:
1919
assert operation[name] == operation.parameters[name]
2020

2121

tests/unit/schema/test_paths.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ def path(self):
1616

1717
@property
1818
def test_iteritems(self, path):
19-
for http_method in path.operations.keys():
19+
for http_method in path.operations:
2020
assert path[http_method] ==\
2121
path.operations[http_method]

tests/unit/schema/test_request_bodies.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ def request_body(self):
1616

1717
@property
1818
def test_iteritems(self, request_body):
19-
for mimetype in request_body.content.keys():
19+
for mimetype in request_body.content:
2020
assert request_body[mimetype] ==\
2121
request_body.content[mimetype]

tests/unit/schema/test_schemas.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def schema(self):
2727

2828
@property
2929
def test_valid(self, schema):
30-
for name in schema.properties.keys():
30+
for name in schema.properties:
3131
assert schema[name] == schema.properties[name]
3232

3333

tests/unit/schema/test_specs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def spec(self, path1, path2):
3232
return Spec(servers, paths)
3333

3434
def test_iteritems(self, spec):
35-
for path_name in spec.paths.keys():
35+
for path_name in spec.paths:
3636
assert spec[path_name] ==\
3737
spec.paths[path_name]
3838

0 commit comments

Comments
 (0)