Skip to content

Commit e8efab6

Browse files
committed
Added autoflake to generation and cleaned up a couple of flake8 issues. Closes #138
1 parent dabc858 commit e8efab6

23 files changed

+60
-53
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818
### Additions
1919

2020
- Endpoints without operationIds will have a name generated from their method and path (#92). Thanks @Kerybas & @dtkav!
21+
- autoflake will be run on generated clients to clean up unused imports / variables (#138). Thanks @pawamoy!
2122
- Note to README about supported OpenAPI versions (#176). Thanks @filippog!
2223

2324
## 0.6.0 - 2020-09-21
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
""" A client library for accessing My Test API """
2-
from .client import AuthenticatedClient, Client

end_to_end_tests/golden-record/my_test_api_client/api/default/ping_ping_get.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
from typing import Any, Dict, List, Optional, Union, cast
1+
from typing import Any, Dict, Optional
22

33
import httpx
4-
from attr import asdict
54

6-
from ...client import AuthenticatedClient, Client
5+
from ...client import Client
76
from ...types import Response
87

98

end_to_end_tests/golden-record/my_test_api_client/api/tests/defaults_tests_defaults_post.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
from typing import Any, Dict, List, Optional, Union, cast
33

44
import httpx
5-
from attr import asdict
65
from dateutil.parser import isoparse
76

8-
from ...client import AuthenticatedClient, Client
7+
from ...client import Client
98
from ...models.an_enum import AnEnum
109
from ...models.http_validation_error import HTTPValidationError
1110
from ...types import Response

end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_booleans.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
from typing import Any, Dict, List, Optional, Union, cast
1+
from typing import Any, Dict, List, Optional, cast
22

33
import httpx
4-
from attr import asdict
54

6-
from ...client import AuthenticatedClient, Client
5+
from ...client import Client
76
from ...types import Response
87

98

end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_floats.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
from typing import Any, Dict, List, Optional, Union, cast
1+
from typing import Any, Dict, List, Optional, cast
22

33
import httpx
4-
from attr import asdict
54

6-
from ...client import AuthenticatedClient, Client
5+
from ...client import Client
76
from ...types import Response
87

98

end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_integers.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
from typing import Any, Dict, List, Optional, Union, cast
1+
from typing import Any, Dict, List, Optional, cast
22

33
import httpx
4-
from attr import asdict
54

6-
from ...client import AuthenticatedClient, Client
5+
from ...client import Client
76
from ...types import Response
87

98

end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_strings.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
from typing import Any, Dict, List, Optional, Union, cast
1+
from typing import Any, Dict, List, Optional, cast
22

33
import httpx
4-
from attr import asdict
54

6-
from ...client import AuthenticatedClient, Client
5+
from ...client import Client
76
from ...types import Response
87

98

end_to_end_tests/golden-record/my_test_api_client/api/tests/get_user_list.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
from typing import Any, Dict, List, Optional, Union, cast
33

44
import httpx
5-
from attr import asdict
6-
from dateutil.parser import isoparse
75

8-
from ...client import AuthenticatedClient, Client
6+
from ...client import Client
97
from ...models.a_model import AModel
108
from ...models.an_enum import AnEnum
119
from ...models.http_validation_error import HTTPValidationError

end_to_end_tests/golden-record/my_test_api_client/api/tests/int_enum_tests_int_enum_post.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
from typing import Any, Dict, List, Optional, Union, cast
1+
from typing import Any, Dict, Optional, Union, cast
22

33
import httpx
4-
from attr import asdict
54

6-
from ...client import AuthenticatedClient, Client
5+
from ...client import Client
76
from ...models.an_int_enum import AnIntEnum
87
from ...models.http_validation_error import HTTPValidationError
98
from ...types import Response

end_to_end_tests/golden-record/my_test_api_client/api/tests/json_body_tests_json_body_post.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
from typing import Any, Dict, List, Optional, Union, cast
1+
from typing import Any, Dict, Optional, Union, cast
22

33
import httpx
4-
from attr import asdict
54

6-
from ...client import AuthenticatedClient, Client
5+
from ...client import Client
76
from ...models.a_model import AModel
87
from ...models.http_validation_error import HTTPValidationError
98
from ...types import Response

end_to_end_tests/golden-record/my_test_api_client/api/tests/no_response_tests_no_response_get.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
from typing import Any, Dict, List, Optional, Union, cast
1+
from typing import Any, Dict
22

33
import httpx
4-
from attr import asdict
54

6-
from ...client import AuthenticatedClient, Client
5+
from ...client import Client
76
from ...types import Response
87

98

end_to_end_tests/golden-record/my_test_api_client/api/tests/octet_stream_tests_octet_stream_get.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
from typing import Any, Dict, List, Optional, Union, cast
1+
from typing import Any, Dict, Optional
22

33
import httpx
4-
from attr import asdict
54

6-
from ...client import AuthenticatedClient, Client
5+
from ...client import Client
76
from ...types import Response
87

98

end_to_end_tests/golden-record/my_test_api_client/api/tests/unsupported_content_tests_unsupported_content_get.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
from typing import Any, Dict, List, Optional, Union, cast
1+
from typing import Any, Dict
22

33
import httpx
4-
from attr import asdict
54

6-
from ...client import AuthenticatedClient, Client
5+
from ...client import Client
76
from ...types import Response
87

98

end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_file_tests_upload_post.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
from typing import Any, Dict, List, Optional, Union, cast
1+
from typing import Any, Dict, Optional, Union, cast
22

33
import httpx
4-
from attr import asdict
54

6-
from ...client import AuthenticatedClient, Client
5+
from ...client import Client
76
from ...models.body_upload_file_tests_upload_post import BodyUploadFileTestsUploadPost
87
from ...models.http_validation_error import HTTPValidationError
98
from ...types import Response
Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1 @@
11
""" Contains all the data models used in inputs/outputs """
2-
3-
from .a_model import AModel
4-
from .an_enum import AnEnum
5-
from .an_int_enum import AnIntEnum
6-
from .body_upload_file_tests_upload_post import BodyUploadFileTestsUploadPost
7-
from .different_enum import DifferentEnum
8-
from .http_validation_error import HTTPValidationError
9-
from .validation_error import ValidationError

end_to_end_tests/golden-record/my_test_api_client/models/a_model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import datetime
2-
from typing import Any, Dict, List, Optional, Union, cast
2+
from typing import Any, Dict, List, Optional, Union
33

44
import attr
55
from dateutil.parser import isoparse
@@ -64,7 +64,7 @@ def _parse_a_camel_date_time(data: Dict[str, Any]) -> Union[datetime.datetime, d
6464
a_camel_date_time = isoparse(d["aCamelDateTime"])
6565

6666
return a_camel_date_time
67-
except:
67+
except: # noqa: E722
6868
pass
6969
a_camel_date_time = isoparse(d["aCamelDateTime"]).date()
7070

end_to_end_tests/golden-record/my_test_api_client/models/http_validation_error.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Dict, List, Optional, cast
1+
from typing import Any, Dict, List, Optional
22

33
import attr
44

openapi_python_client/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ def update(self) -> Sequence[GeneratorError]:
7575
return self._get_errors()
7676

7777
def _reformat(self) -> None:
78+
subprocess.run(
79+
"autoflake -i -r --remove-all-unused-imports --remove-unused-variables .",
80+
cwd=self.package_dir,
81+
shell=True,
82+
stdout=subprocess.PIPE,
83+
stderr=subprocess.PIPE,
84+
)
7885
subprocess.run(
7986
"isort .",
8087
cwd=self.project_dir,

openapi_python_client/templates/property_templates/union_property.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def _parse_{{ property.python_name }}(data: Dict[str, Any]) -> {{ property.get_t
77
{% from "property_templates/" + inner_property.template import construct %}
88
{{ construct(inner_property, source) | indent(8) }}
99
return {{ property.python_name }}
10-
except:
10+
except: # noqa: E722
1111
pass
1212
{% elif inner_property.template and loop.last %}{# Don't do try/except for the last one #}
1313
{% from "property_templates/" + inner_property.template import construct %}

poetry.lock

Lines changed: 16 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pydantic = "^1.6.1"
3333
attrs = "^20.1.0"
3434
python-dateutil = "^2.8.1"
3535
httpx = "^0.15.4"
36+
autoflake = "^1.4"
3637

3738
[tool.poetry.scripts]
3839
openapi-python-client = "openapi_python_client.cli:app"

tests/test___init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,13 @@ def test__reformat(mocker):
381381

382382
sub_run.assert_has_calls(
383383
[
384+
mocker.call(
385+
"autoflake -i -r --remove-all-unused-imports --remove-unused-variables .",
386+
cwd=project.package_dir,
387+
shell=True,
388+
stdout=subprocess.PIPE,
389+
stderr=subprocess.PIPE,
390+
),
384391
mocker.call(
385392
"isort .",
386393
cwd=project.project_dir,

0 commit comments

Comments
 (0)