Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

Commit d75e7ad

Browse files
authored
Fixes mypy redundant casts issue (#251)
* Adds uncast returns if property type is the same as the map value type * Petstore regen with redundant casts removed * Adds 3 patch tests of typing.cast * Updates samples
1 parent d491313 commit d75e7ad

File tree

76 files changed

+164
-411
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+164
-411
lines changed

samples/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/additionalproperties_are_allowed_by_default.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,14 @@ def foo(self) -> typing.Union[schemas.OUTPUT_BASE_TYPES, schemas.Unset]:
7373
val = self.get("foo", schemas.unset)
7474
if isinstance(val, schemas.Unset):
7575
return val
76-
return typing.cast(
77-
schemas.OUTPUT_BASE_TYPES,
78-
val
79-
)
76+
return val
8077

8178
@property
8279
def bar(self) -> typing.Union[schemas.OUTPUT_BASE_TYPES, schemas.Unset]:
8380
val = self.get("bar", schemas.unset)
8481
if isinstance(val, schemas.Unset):
8582
return val
86-
return typing.cast(
87-
schemas.OUTPUT_BASE_TYPES,
88-
val
89-
)
83+
return val
9084

9185
def get_additional_property_(self, name: str) -> typing.Union[schemas.OUTPUT_BASE_TYPES, schemas.Unset]:
9286
schemas.raise_if_key_known(name, self.__required_keys__, self.__optional_keys__)

samples/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/additionalproperties_should_not_look_in_applicators.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,7 @@ def foo(self) -> typing.Union[schemas.OUTPUT_BASE_TYPES, schemas.Unset]:
6565
val = self.get("foo", schemas.unset)
6666
if isinstance(val, schemas.Unset):
6767
return val
68-
return typing.cast(
69-
schemas.OUTPUT_BASE_TYPES,
70-
val
71-
)
68+
return val
7269

7370
def get_additional_property_(self, name: str) -> typing.Union[schemas.OUTPUT_BASE_TYPES, schemas.Unset]:
7471
schemas.raise_if_key_known(name, self.__required_keys__, self.__optional_keys__)

samples/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/allof.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,7 @@ def from_dict_(
125125

126126
@property
127127
def foo(self) -> str:
128-
return typing.cast(
129-
str,
130-
self.__getitem__("foo")
131-
)
128+
return self.__getitem__("foo")
132129

133130
def get_additional_property_(self, name: str) -> typing.Union[schemas.OUTPUT_BASE_TYPES, schemas.Unset]:
134131
schemas.raise_if_key_known(name, self.__required_keys__, self.__optional_keys__)

samples/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/allof_with_base_schema.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,7 @@ def from_dict_(
5353

5454
@property
5555
def foo(self) -> str:
56-
return typing.cast(
57-
str,
58-
self.__getitem__("foo")
59-
)
56+
return self.__getitem__("foo")
6057

6158
def get_additional_property_(self, name: str) -> typing.Union[schemas.OUTPUT_BASE_TYPES, schemas.Unset]:
6259
schemas.raise_if_key_known(name, self.__required_keys__, self.__optional_keys__)
@@ -125,10 +122,7 @@ def from_dict_(
125122

126123
@property
127124
def baz(self) -> None:
128-
return typing.cast(
129-
None,
130-
self.__getitem__("baz")
131-
)
125+
return self.__getitem__("baz")
132126

133127
def get_additional_property_(self, name: str) -> typing.Union[schemas.OUTPUT_BASE_TYPES, schemas.Unset]:
134128
schemas.raise_if_key_known(name, self.__required_keys__, self.__optional_keys__)

samples/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/anyof_complex_types.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,7 @@ def from_dict_(
125125

126126
@property
127127
def foo(self) -> str:
128-
return typing.cast(
129-
str,
130-
self.__getitem__("foo")
131-
)
128+
return self.__getitem__("foo")
132129

133130
def get_additional_property_(self, name: str) -> typing.Union[schemas.OUTPUT_BASE_TYPES, schemas.Unset]:
134131
schemas.raise_if_key_known(name, self.__required_keys__, self.__optional_keys__)

samples/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/invalid_string_value_for_default.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,7 @@ def bar(self) -> typing.Union[str, schemas.Unset]:
7373
val = self.get("bar", schemas.unset)
7474
if isinstance(val, schemas.Unset):
7575
return val
76-
return typing.cast(
77-
str,
78-
val
79-
)
76+
return val
8077

8178
def get_additional_property_(self, name: str) -> typing.Union[schemas.OUTPUT_BASE_TYPES, schemas.Unset]:
8279
schemas.raise_if_key_known(name, self.__required_keys__, self.__optional_keys__)

samples/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/not_more_complex_schema.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,7 @@ def foo(self) -> typing.Union[str, schemas.Unset]:
6363
val = self.get("foo", schemas.unset)
6464
if isinstance(val, schemas.Unset):
6565
return val
66-
return typing.cast(
67-
str,
68-
val
69-
)
66+
return val
7067

7168
def get_additional_property_(self, name: str) -> typing.Union[schemas.OUTPUT_BASE_TYPES, schemas.Unset]:
7269
schemas.raise_if_key_known(name, self.__required_keys__, self.__optional_keys__)

samples/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/oneof_complex_types.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,7 @@ def from_dict_(
125125

126126
@property
127127
def foo(self) -> str:
128-
return typing.cast(
129-
str,
130-
self.__getitem__("foo")
131-
)
128+
return self.__getitem__("foo")
132129

133130
def get_additional_property_(self, name: str) -> typing.Union[schemas.OUTPUT_BASE_TYPES, schemas.Unset]:
134131
schemas.raise_if_key_known(name, self.__required_keys__, self.__optional_keys__)

samples/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/required_default_validation.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,7 @@ def foo(self) -> typing.Union[schemas.OUTPUT_BASE_TYPES, schemas.Unset]:
6464
val = self.get("foo", schemas.unset)
6565
if isinstance(val, schemas.Unset):
6666
return val
67-
return typing.cast(
68-
schemas.OUTPUT_BASE_TYPES,
69-
val
70-
)
67+
return val
7168

7269
def get_additional_property_(self, name: str) -> typing.Union[schemas.OUTPUT_BASE_TYPES, schemas.Unset]:
7370
schemas.raise_if_key_known(name, self.__required_keys__, self.__optional_keys__)

samples/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/required_validation.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,14 @@ def from_dict_(
7070

7171
@property
7272
def foo(self) -> schemas.OUTPUT_BASE_TYPES:
73-
return typing.cast(
74-
schemas.OUTPUT_BASE_TYPES,
75-
self.__getitem__("foo")
76-
)
73+
return self.__getitem__("foo")
7774

7875
@property
7976
def bar(self) -> typing.Union[schemas.OUTPUT_BASE_TYPES, schemas.Unset]:
8077
val = self.get("bar", schemas.unset)
8178
if isinstance(val, schemas.Unset):
8279
return val
83-
return typing.cast(
84-
schemas.OUTPUT_BASE_TYPES,
85-
val
86-
)
80+
return val
8781

8882
def get_additional_property_(self, name: str) -> typing.Union[schemas.OUTPUT_BASE_TYPES, schemas.Unset]:
8983
schemas.raise_if_key_known(name, self.__required_keys__, self.__optional_keys__)

0 commit comments

Comments
 (0)