Skip to content

Commit ba13956

Browse files
committed
Remove wrong model_parent argument in Property.get_type_string
1 parent aaf3c70 commit ba13956

File tree

5 files changed

+6
-29
lines changed

5 files changed

+6
-29
lines changed

openapi_python_client/parser/properties/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,6 @@ def get_type_string(
270270
no_optional: bool = False,
271271
json: bool = False,
272272
*,
273-
model_parent: Optional[ModelProperty] = None, # pylint:disable=unused-argument
274273
quoted: bool = False,
275274
) -> str:
276275
"""

openapi_python_client/parser/properties/model_property.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ def get_type_string(
9292
no_optional: bool = False,
9393
json: bool = False,
9494
*,
95-
model_parent: Optional[ModelProperty] = None,
9695
quoted: bool = False,
9796
) -> str:
9897
"""
@@ -108,10 +107,6 @@ def get_type_string(
108107
type_string = self.get_base_type_string()
109108

110109
if quoted:
111-
if model_parent:
112-
if type_string == model_parent.class_info.name:
113-
type_string = f"'{type_string}'"
114-
115110
if type_string == self.class_info.name:
116111
type_string = f"'{type_string}'"
117112

openapi_python_client/parser/properties/property.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ def get_type_string(
7878
no_optional: bool = False,
7979
json: bool = False,
8080
*,
81-
model_parent: Optional[ModelProperty] = None,
8281
quoted: bool = False,
8382
) -> str:
8483
"""
@@ -133,12 +132,8 @@ def get_lazy_imports(self, *, prefix: str) -> Set[str]:
133132
"""
134133
return set()
135134

136-
def to_string(self, *, model_parent: Optional[ModelProperty] = None) -> str:
137-
"""How this should be declared in a dataclass
138-
139-
Args:
140-
model_parent: The ModelProperty which contains this Property (used for template type annotations)
141-
"""
135+
def to_string(self) -> str:
136+
"""How this should be declared in a dataclass"""
142137
default: Optional[str]
143138
if self.default is not None:
144139
default = self.default
@@ -148,8 +143,8 @@ def to_string(self, *, model_parent: Optional[ModelProperty] = None) -> str:
148143
default = None
149144

150145
if default is not None:
151-
return f"{self.python_name}: {self.get_type_string(model_parent=model_parent, quoted=True)} = {default}"
152-
return f"{self.python_name}: {self.get_type_string(model_parent=model_parent, quoted=True)}"
146+
return f"{self.python_name}: {self.get_type_string(quoted=True)} = {default}"
147+
return f"{self.python_name}: {self.get_type_string(quoted=True)}"
153148

154149
def to_docstring(self) -> str:
155150
"""Returns property docstring"""

openapi_python_client/templates/model.py.jinja

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ if TYPE_CHECKING:
2525

2626

2727
{% if model.additional_properties %}
28-
{% set additional_property_type = 'Any' if model.additional_properties == True else model.additional_properties.get_type_string(model_parent=model, quoted=not model.additional_properties.is_base_type) %}
28+
{% set additional_property_type = 'Any' if model.additional_properties == True else model.additional_properties.get_type_string(quoted=not model.additional_properties.is_base_type) %}
2929
{% endif %}
3030

3131
{% set class_name = model.class_info.name %}
@@ -64,7 +64,7 @@ class {{ class_name }}:
6464
{% endfor %}
6565
{% for property in model.required_properties + model.optional_properties %}
6666
{% if property.default is not none or not property.required %}
67-
{{ property.to_string(model_parent=model) }}
67+
{{ property.to_string() }}
6868
{% endif %}
6969
{% endfor %}
7070
{% if model.additional_properties %}

tests/test_parser/test_properties/test_model_property.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,6 @@ def test_get_imports(self, model_property_factory):
5454
"from typing import cast",
5555
}
5656

57-
@pytest.mark.parametrize(
58-
"quoted,expected",
59-
[
60-
(False, "MyClass"),
61-
(True, "'MyClass'"),
62-
],
63-
)
64-
def test_get_type_string_parent(self, model_property_factory, quoted, expected):
65-
parent = model_property_factory()
66-
m = model_property_factory()
67-
assert m.get_type_string(model_parent=parent, quoted=quoted) == expected
68-
6957
def test_get_lazy_imports(self, model_property_factory):
7058
prop = model_property_factory(required=False, nullable=True)
7159

0 commit comments

Comments
 (0)