Skip to content

Commit 92b907e

Browse files
committed
Fix mypy for datetime properties
Have to cast the string value to a string in the from_dict function of models with a datetime property.
1 parent 4fe06fd commit 92b907e

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,8 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7-
## 0.1.0 - YYYY-MM-DD
7+
## 0.1.1 - 2020-03-06
8+
- Fix mypy issue in generated models with datetime properties
9+
10+
## 0.1.0 - 2020-02-28
811
- Initial Release

openapi_python_client/templates/datetime_property.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
{% else %}
44
{{ property.name }} = None
55
if ({{ property.name }}_string := d.get("{{ property.name }}")) is not None:
6-
{{ property.name }} = datetime.fromisoformat({{ property.name }}_string)
6+
{{ property.name }} = datetime.fromisoformat(cast(str, {{ property.name }}_string))
77
{% endif %}

openapi_python_client/templates/model.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ from __future__ import annotations
22

33
from dataclasses import dataclass
44
from datetime import datetime
5-
from typing import Dict, List, Optional
5+
from typing import Dict, List, Optional, cast
66

77
{% for relative in schema.relative_imports %}
88
{{ relative }}

0 commit comments

Comments
 (0)