diff --git a/openapi_python_client/parser/properties/property.py b/openapi_python_client/parser/properties/property.py index c0ec0d56e..542e2a5f7 100644 --- a/openapi_python_client/parser/properties/property.py +++ b/openapi_python_client/parser/properties/property.py @@ -62,11 +62,7 @@ def get_type_string(self, no_optional: bool = False, query_parameter: bool = Fal if self.nullable: return f"Union[Unset, None, {type_string}]" else: - if query_parameter: - # For query parameters, None has the same meaning as Unset - return f"Union[Unset, None, {type_string}]" - else: - return f"Union[Unset, {type_string}]" + return f"Union[Unset, {type_string}]" def get_instance_type_string(self) -> str: """Get a string representation of runtime type that should be used for `isinstance` checks""" diff --git a/openapi_python_client/templates/property_templates/date_property.pyi b/openapi_python_client/templates/property_templates/date_property.pyi index d883d8787..528a9961b 100644 --- a/openapi_python_client/templates/property_templates/date_property.pyi +++ b/openapi_python_client/templates/property_templates/date_property.pyi @@ -17,7 +17,7 @@ if _{{ property.python_name }} is not None: {% else %} {{ destination }}{% if declare_type %}: {{ property.get_type_string(query_parameter=query_parameter, json=True) }}{% endif %} = UNSET if not isinstance({{ source }}, Unset): -{% if property.nullable or query_parameter %} +{% if property.nullable %} {{ destination }} = {{ source }}.isoformat() if {{ source }} else None {% else %} {{ destination }} = {{ source }}.isoformat() diff --git a/openapi_python_client/templates/property_templates/datetime_property.pyi b/openapi_python_client/templates/property_templates/datetime_property.pyi index 53f432a59..5442c75fe 100644 --- a/openapi_python_client/templates/property_templates/datetime_property.pyi +++ b/openapi_python_client/templates/property_templates/datetime_property.pyi @@ -26,7 +26,7 @@ if _{{ property.python_name }} is not None: {% else %} {{ destination }}{% if declare_type %}: {{ property.get_type_string(query_parameter=query_parameter, json=True) }}{% endif %} = UNSET if not isinstance({{ source }}, Unset): -{% if property.nullable or query_parameter %} +{% if property.nullable %} {{ destination }} = {{ source }}.isoformat() if {{ source }} else None {% else %} {{ destination }} = {{ source }}.isoformat() diff --git a/openapi_python_client/templates/property_templates/enum_property.pyi b/openapi_python_client/templates/property_templates/enum_property.pyi index 764e66ade..4c33ba051 100644 --- a/openapi_python_client/templates/property_templates/enum_property.pyi +++ b/openapi_python_client/templates/property_templates/enum_property.pyi @@ -21,7 +21,7 @@ if _{{ property.python_name }} is not None and _{{ property.python_name }} is no {% else %} {{ destination }}{% if declare_type %}: {{ property.get_type_string(query_parameter=query_parameter, json=True) }}{% endif %} = UNSET if not isinstance({{ source }}, Unset): -{% if property.nullable or query_parameter %} +{% if property.nullable %} {{ destination }} = {{ source }}.value if {{ source }} else None {% else %} {{ destination }} = {{ source }}.value diff --git a/openapi_python_client/templates/property_templates/file_property.pyi b/openapi_python_client/templates/property_templates/file_property.pyi index 3a5b5e746..1758c07f6 100644 --- a/openapi_python_client/templates/property_templates/file_property.pyi +++ b/openapi_python_client/templates/property_templates/file_property.pyi @@ -16,7 +16,7 @@ {% else %} {{ destination }}{% if declare_type %}: {{ property.get_type_string(query_parameter=query_parameter, json=True) }}{% endif %} = UNSET if not isinstance({{ source }}, Unset): -{% if property.nullable or query_parameter %} +{% if property.nullable %} {{ destination }} = {{ source }}.to_tuple() if {{ source }} else None {% else %} {{ destination }} = {{ source }}.to_tuple() diff --git a/openapi_python_client/templates/property_templates/list_property.pyi b/openapi_python_client/templates/property_templates/list_property.pyi index 6f2d03f68..0705e9d93 100644 --- a/openapi_python_client/templates/property_templates/list_property.pyi +++ b/openapi_python_client/templates/property_templates/list_property.pyi @@ -48,7 +48,7 @@ else: {% else %} {{ destination }}{% if declare_type %}: {{ property.get_type_string(query_parameter=query_parameter, json=True) }}{% endif %} = UNSET if not isinstance({{ source }}, Unset): -{% if property.nullable or query_parameter %} +{% if property.nullable %} if {{ source }} is None: {{ destination }} = None else: diff --git a/openapi_python_client/templates/property_templates/model_property.pyi b/openapi_python_client/templates/property_templates/model_property.pyi index 1cabf2996..40a8a8b78 100644 --- a/openapi_python_client/templates/property_templates/model_property.pyi +++ b/openapi_python_client/templates/property_templates/model_property.pyi @@ -27,7 +27,7 @@ if {% if property.nullable %}_{{ property.python_name }} is not None{% endif %}{ {% else %} {{ destination }}{% if declare_type %}: {{ property.get_type_string(query_parameter=query_parameter, json=True) }}{% endif %} = UNSET if not isinstance({{ source }}, Unset): -{% if property.nullable or query_parameter %} +{% if property.nullable %} {{ destination }} = {{ source }}.to_dict() if {{ source }} else None {% else %} {{ destination }} = {{ source }}.to_dict() diff --git a/openapi_python_client/templates/property_templates/union_property.pyi b/openapi_python_client/templates/property_templates/union_property.pyi index c414fb65d..179dd4ae3 100644 --- a/openapi_python_client/templates/property_templates/union_property.pyi +++ b/openapi_python_client/templates/property_templates/union_property.pyi @@ -45,7 +45,7 @@ def _parse_{{ property.python_name }}(data: {{ property.get_type_string(json=Tru if isinstance({{ source }}, Unset): {{ destination }} = UNSET {% endif %} -{% if property.nullable or (query_parameter and not property.required) %} +{% if property.nullable %} {% if property.required %} if {{ source }} is None: {% else %}{# There's an if UNSET statement before this #}