Skip to content

Commit cc2ebc9

Browse files
renovate[bot]Copilotdbanty
authored
fix: Remove some generated casts that aren't necessary with mypy v2 (#1436)
This PR contains the following updates: | Update | Change | |---|---| | lockFileMaintenance | All locks refreshed | 🔧 This Pull Request updates lock files to use the latest dependency versions. --- ### Configuration 📅 **Schedule**: (UTC) - Branch creation - "before 4am on monday" - Automerge - At any time (no schedule defined) 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 👻 **Immortal**: This PR will be recreated if closed unmerged. Get [config help](https://redirect.github.com/renovatebot/renovate/discussions) if that's undesired. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/openapi-generators/openapi-python-client). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4xNzkuMyIsInVwZGF0ZWRJblZlciI6IjQzLjE4Mi4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119--> --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: dbanty <43723790+dbanty@users.noreply.github.com>
1 parent 284576f commit cc2ebc9

11 files changed

Lines changed: 880 additions & 764 deletions

File tree

end_to_end_tests/literal-enums-golden-record/my_enum_api_client/models/an_all_of_enum.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Literal, cast
1+
from typing import Literal
22

33
AnAllOfEnum = Literal["a_default", "bar", "foo", "overridden_default"]
44

@@ -12,5 +12,5 @@
1212

1313
def check_an_all_of_enum(value: str) -> AnAllOfEnum:
1414
if value in AN_ALL_OF_ENUM_VALUES:
15-
return cast(AnAllOfEnum, value)
15+
return value
1616
raise TypeError(f"Unexpected value {value!r}. Expected one of {AN_ALL_OF_ENUM_VALUES!r}")

end_to_end_tests/literal-enums-golden-record/my_enum_api_client/models/an_enum.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Literal, cast
1+
from typing import Literal
22

33
AnEnum = Literal["FIRST_VALUE", "SECOND_VALUE"]
44

@@ -10,5 +10,5 @@
1010

1111
def check_an_enum(value: str) -> AnEnum:
1212
if value in AN_ENUM_VALUES:
13-
return cast(AnEnum, value)
13+
return value
1414
raise TypeError(f"Unexpected value {value!r}. Expected one of {AN_ENUM_VALUES!r}")

end_to_end_tests/literal-enums-golden-record/my_enum_api_client/models/an_enum_with_null.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Literal, cast
1+
from typing import Literal
22

33
AnEnumWithNull = Literal["FIRST_VALUE", "SECOND_VALUE"]
44

@@ -10,5 +10,5 @@
1010

1111
def check_an_enum_with_null(value: str) -> AnEnumWithNull:
1212
if value in AN_ENUM_WITH_NULL_VALUES:
13-
return cast(AnEnumWithNull, value)
13+
return value
1414
raise TypeError(f"Unexpected value {value!r}. Expected one of {AN_ENUM_WITH_NULL_VALUES!r}")

end_to_end_tests/literal-enums-golden-record/my_enum_api_client/models/an_int_enum.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Literal, cast
1+
from typing import Literal
22

33
AnIntEnum = Literal[-1, 1, 2]
44

@@ -11,5 +11,5 @@
1111

1212
def check_an_int_enum(value: int) -> AnIntEnum:
1313
if value in AN_INT_ENUM_VALUES:
14-
return cast(AnIntEnum, value)
14+
return value
1515
raise TypeError(f"Unexpected value {value!r}. Expected one of {AN_INT_ENUM_VALUES!r}")

end_to_end_tests/literal-enums-golden-record/my_enum_api_client/models/different_enum.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Literal, cast
1+
from typing import Literal
22

33
DifferentEnum = Literal["DIFFERENT", "OTHER"]
44

@@ -10,5 +10,5 @@
1010

1111
def check_different_enum(value: str) -> DifferentEnum:
1212
if value in DIFFERENT_ENUM_VALUES:
13-
return cast(DifferentEnum, value)
13+
return value
1414
raise TypeError(f"Unexpected value {value!r}. Expected one of {DIFFERENT_ENUM_VALUES!r}")

end_to_end_tests/literal-enums-golden-record/my_enum_api_client/models/get_user_list_int_enum_header.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Literal, cast
1+
from typing import Literal
22

33
GetUserListIntEnumHeader = Literal[1, 2, 3]
44

@@ -11,5 +11,5 @@
1111

1212
def check_get_user_list_int_enum_header(value: int) -> GetUserListIntEnumHeader:
1313
if value in GET_USER_LIST_INT_ENUM_HEADER_VALUES:
14-
return cast(GetUserListIntEnumHeader, value)
14+
return value
1515
raise TypeError(f"Unexpected value {value!r}. Expected one of {GET_USER_LIST_INT_ENUM_HEADER_VALUES!r}")

end_to_end_tests/literal-enums-golden-record/my_enum_api_client/models/get_user_list_string_enum_header.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Literal, cast
1+
from typing import Literal
22

33
GetUserListStringEnumHeader = Literal["one", "three", "two"]
44

@@ -11,5 +11,5 @@
1111

1212
def check_get_user_list_string_enum_header(value: str) -> GetUserListStringEnumHeader:
1313
if value in GET_USER_LIST_STRING_ENUM_HEADER_VALUES:
14-
return cast(GetUserListStringEnumHeader, value)
14+
return value
1515
raise TypeError(f"Unexpected value {value!r}. Expected one of {GET_USER_LIST_STRING_ENUM_HEADER_VALUES!r}")

end_to_end_tests/test_end_to_end.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import shutil
2+
import subprocess
3+
import sys
24
from filecmp import cmpfiles, dircmp
35
from pathlib import Path
46

@@ -99,10 +101,12 @@ def run_e2e_test(
99101
gr_path, g.output_path, expected_differences=expected_differences, expected_missing=expected_missing
100102
)
101103

102-
import mypy.api
103-
104-
out, err, status = mypy.api.run([str(g.output_path), "--strict"])
105-
assert status == 0, f"Type checking client failed: {out}"
104+
result = subprocess.run(
105+
[sys.executable, "-m", "mypy", str(g.output_path), "--strict"],
106+
capture_output=True,
107+
text=True,
108+
)
109+
assert result.returncode == 0, f"Type checking client failed: {result.stdout}"
106110

107111
return g.generator_result
108112

@@ -281,10 +285,12 @@ def test_update_integration_tests():
281285
config_path=config_path
282286
)
283287
_compare_directories(source_path, temp_dir, ignore=["pyproject.toml"])
284-
import mypy.api
285-
286-
out, err, status = mypy.api.run([str(temp_dir), "--strict"])
287-
assert status == 0, f"Type checking client failed: {out=} {err=}"
288+
result = subprocess.run(
289+
[sys.executable, "-m", "mypy", str(temp_dir), "--strict"],
290+
capture_output=True,
291+
text=True,
292+
)
293+
assert result.returncode == 0, f"Type checking client failed: {result.stdout=} {result.stderr=}"
288294

289295
finally:
290296
shutil.rmtree(temp_dir)

integration-tests/pdm.lock

Lines changed: 249 additions & 193 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
from typing import Literal, cast
1+
from typing import Literal
22

33
{{ enum.class_info.name }} = Literal{{ "%r" | format(enum.values|list|sort) }}
44

55
{{ enum.get_class_name_snake_case() | upper }}_VALUES: set[{{ enum.class_info.name }}] = { {% for v in enum.values|list|sort %}{{"%r"|format(v)}}, {% endfor %} }
66

77
def check_{{ enum.get_class_name_snake_case() }}(value: {{ enum.get_instance_type_string() }}) -> {{ enum.class_info.name}}:
88
if value in {{ enum.get_class_name_snake_case() | upper }}_VALUES:
9-
return cast({{enum.class_info.name}}, value)
9+
return value
1010
raise TypeError(f"Unexpected value {value!r}. Expected one of {{"{"}}{{ enum.get_class_name_snake_case() | upper }}_VALUES!r}")

0 commit comments

Comments
 (0)