python: simplify module imports (#17507)

In #16624, I introduced a new mechanism to record imports to other
modules, instead of having specialized datetime/typing/pydantic objects
to manage imports for these modules.

This change reuses the mechanism from #16624 and replace the specialized
import managers by the generic one. Unused imports from various
.mustache templates are also cleaned up.
This commit is contained in:
Jonathan Ballet
2024-01-03 14:22:53 +01:00
committed by GitHub
parent dffb5c121f
commit 063865973d
266 changed files with 356 additions and 1335 deletions

View File

@@ -50,7 +50,6 @@ Please follow the [installation procedure](#installation--usage) and then run th
```python
import time
import openapi_client
from openapi_client.rest import ApiException
from pprint import pprint

View File

@@ -20,8 +20,6 @@ To test HTTP basic authentication
* Basic Authentication (http_auth):
```python
import time
import os
import openapi_client
from openapi_client.rest import ApiException
from pprint import pprint
@@ -96,8 +94,6 @@ To test HTTP bearer authentication
* Bearer Authentication (http_bearer_auth):
```python
import time
import os
import openapi_client
from openapi_client.rest import ApiException
from pprint import pprint

View File

@@ -26,8 +26,6 @@ Test binary (gif) response body
```python
import time
import os
import openapi_client
from openapi_client.rest import ApiException
from pprint import pprint
@@ -91,8 +89,6 @@ Test body parameter(s)
```python
import time
import os
import openapi_client
from openapi_client.rest import ApiException
from pprint import pprint
@@ -160,8 +156,6 @@ Test array of binary in multipart mime
```python
import time
import os
import openapi_client
from openapi_client.rest import ApiException
from pprint import pprint
@@ -229,8 +223,6 @@ Test single binary in multipart mime
```python
import time
import os
import openapi_client
from openapi_client.rest import ApiException
from pprint import pprint
@@ -298,8 +290,6 @@ Test body parameter(s)
```python
import time
import os
import openapi_client
from openapi_client.models.pet import Pet
from openapi_client.rest import ApiException
@@ -368,8 +358,6 @@ Test free form object
```python
import time
import os
import openapi_client
from openapi_client.rest import ApiException
from pprint import pprint
@@ -437,8 +425,6 @@ Test body parameter(s)
```python
import time
import os
import openapi_client
from openapi_client.models.pet import Pet
from openapi_client.rest import ApiException
@@ -507,8 +493,6 @@ Test empty response body
```python
import time
import os
import openapi_client
from openapi_client.models.pet import Pet
from openapi_client.rest import ApiException
@@ -577,8 +561,6 @@ Test empty json (request body)
```python
import time
import os
import openapi_client
from openapi_client.models.tag import Tag
from openapi_client.rest import ApiException

View File

@@ -19,8 +19,6 @@ Test form parameter(s)
```python
import time
import os
import openapi_client
from openapi_client.rest import ApiException
from pprint import pprint
@@ -92,8 +90,6 @@ Test form parameter(s) for oneOf schema
```python
import time
import os
import openapi_client
from openapi_client.rest import ApiException
from pprint import pprint

View File

@@ -18,8 +18,6 @@ Test header parameter(s)
```python
import time
import os
import openapi_client
from openapi_client.models.string_enum_ref import StringEnumRef
from openapi_client.rest import ApiException

View File

@@ -18,8 +18,6 @@ Test path parameter(s)
```python
import time
import os
import openapi_client
from openapi_client.models.string_enum_ref import StringEnumRef
from openapi_client.rest import ApiException

View File

@@ -25,8 +25,6 @@ Test query parameter(s)
```python
import time
import os
import openapi_client
from openapi_client.models.string_enum_ref import StringEnumRef
from openapi_client.rest import ApiException
@@ -97,8 +95,6 @@ Test query parameter(s)
```python
import time
import os
import openapi_client
from openapi_client.rest import ApiException
from pprint import pprint
@@ -170,8 +166,6 @@ Test query parameter(s)
```python
import time
import os
import openapi_client
from openapi_client.rest import ApiException
from pprint import pprint
@@ -243,8 +237,6 @@ Test query parameter(s)
```python
import time
import os
import openapi_client
from openapi_client.models.pet import Pet
from openapi_client.rest import ApiException
@@ -313,8 +305,6 @@ Test query parameter(s)
```python
import time
import os
import openapi_client
from openapi_client.rest import ApiException
from pprint import pprint
@@ -382,8 +372,6 @@ Test query parameter(s)
```python
import time
import os
import openapi_client
from openapi_client.models.test_query_style_form_explode_true_array_string_query_object_parameter import TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter
from openapi_client.rest import ApiException
@@ -452,8 +440,6 @@ Test query parameter(s)
```python
import time
import os
import openapi_client
from openapi_client.models.pet import Pet
from openapi_client.rest import ApiException
@@ -522,8 +508,6 @@ Test query parameter(s)
```python
import time
import os
import openapi_client
from openapi_client.rest import ApiException
from pprint import pprint

View File

@@ -12,12 +12,9 @@
Do not edit the class manually.
""" # noqa: E501
import io
import warnings
from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt
from typing import Dict, List, Optional, Tuple, Union, Any
from typing import Any, Dict, List, Optional, Tuple, Union
try:
from typing import Annotated

View File

@@ -12,24 +12,18 @@
Do not edit the class manually.
""" # noqa: E501
import io
import warnings
from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt
from typing import Dict, List, Optional, Tuple, Union, Any
from typing import Any, Dict, List, Optional, Tuple, Union
try:
from typing import Annotated
except ImportError:
from typing_extensions import Annotated
from pydantic import Field
from typing_extensions import Annotated
from pydantic import StrictBytes, StrictStr
from pydantic import Field, StrictBytes, StrictStr
from typing import Any, Dict, List, Optional, Union
from typing_extensions import Annotated
from openapi_client.models.pet import Pet
from openapi_client.models.tag import Tag
@@ -519,7 +513,7 @@ class BodyApi:
if body is not None:
# convert to byte array if the input is a file name (str)
if isinstance(body, str):
with io.open(body, "rb") as _fp:
with open(body, "rb") as _fp:
_body_params = _fp.read()
else:
_body_params = body

View File

@@ -12,12 +12,9 @@
Do not edit the class manually.
""" # noqa: E501
import io
import warnings
from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt
from typing import Dict, List, Optional, Tuple, Union, Any
from typing import Any, Dict, List, Optional, Tuple, Union
try:
from typing import Annotated
@@ -25,10 +22,8 @@ except ImportError:
from typing_extensions import Annotated
from pydantic import StrictBool, StrictInt, StrictStr
from typing import Optional
from openapi_client.api_client import ApiClient
from openapi_client.api_response import ApiResponse
from openapi_client.rest import RESTResponseType

View File

@@ -12,12 +12,9 @@
Do not edit the class manually.
""" # noqa: E501
import io
import warnings
from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt
from typing import Dict, List, Optional, Tuple, Union, Any
from typing import Any, Dict, List, Optional, Tuple, Union
try:
from typing import Annotated
@@ -25,9 +22,7 @@ except ImportError:
from typing_extensions import Annotated
from pydantic import StrictBool, StrictInt, StrictStr, field_validator
from typing import Optional
from openapi_client.models.string_enum_ref import StringEnumRef
from openapi_client.api_client import ApiClient

View File

@@ -12,12 +12,9 @@
Do not edit the class manually.
""" # noqa: E501
import io
import warnings
from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt
from typing import Dict, List, Optional, Tuple, Union, Any
from typing import Any, Dict, List, Optional, Tuple, Union
try:
from typing import Annotated
@@ -25,7 +22,6 @@ except ImportError:
from typing_extensions import Annotated
from pydantic import StrictInt, StrictStr, field_validator
from openapi_client.models.string_enum_ref import StringEnumRef
from openapi_client.api_client import ApiClient

View File

@@ -12,12 +12,9 @@
Do not edit the class manually.
""" # noqa: E501
import io
import warnings
from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt
from typing import Dict, List, Optional, Tuple, Union, Any
from typing import Any, Dict, List, Optional, Tuple, Union
try:
from typing import Annotated
@@ -25,11 +22,8 @@ except ImportError:
from typing_extensions import Annotated
from datetime import date, datetime
from pydantic import StrictBool, StrictInt, StrictStr, field_validator
from typing import Any, Optional
from openapi_client.models.pet import Pet
from openapi_client.models.string_enum_ref import StringEnumRef
from openapi_client.models.test_query_style_form_explode_true_array_string_query_object_parameter import TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter

View File

@@ -13,7 +13,6 @@
""" # noqa: E501
import atexit
import datetime
from dateutil.parser import parse
import json

View File

@@ -1,7 +1,7 @@
"""API response object."""
from __future__ import annotations
from typing import Any, Dict, Optional, Generic, TypeVar
from typing import Dict, Optional, Generic, TypeVar
from pydantic import Field, StrictInt, StrictStr, StrictBytes, BaseModel
T = TypeVar("T")

View File

@@ -18,9 +18,8 @@ import pprint
import re # noqa: F401
import json
from typing import Any, ClassVar, Dict, List, Optional
from pydantic import BaseModel, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
try:
from typing import Self
except ImportError:

View File

@@ -18,9 +18,8 @@ import pprint
import re # noqa: F401
import json
from typing import Any, ClassVar, Dict, List, Optional
from pydantic import BaseModel, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
try:
from typing import Self
except ImportError:

View File

@@ -19,9 +19,8 @@ import re # noqa: F401
import json
from datetime import datetime
from pydantic import Field, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from pydantic import StrictStr
from pydantic import Field
from openapi_client.models.query import Query
try:
from typing import Self

View File

@@ -18,9 +18,8 @@ import pprint
import re # noqa: F401
import json
from typing import Any, ClassVar, Dict, List, Optional
from pydantic import BaseModel, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from openapi_client.models.string_enum_ref import StringEnumRef
try:
from typing import Self

View File

@@ -18,10 +18,8 @@ import pprint
import re # noqa: F401
import json
from pydantic import BaseModel, Field, StrictFloat, StrictInt
from typing import Any, ClassVar, Dict, List, Optional, Union
from pydantic import BaseModel, StrictFloat, StrictInt
from pydantic import Field
from typing_extensions import Annotated
try:
from typing import Self

View File

@@ -18,10 +18,8 @@ import pprint
import re # noqa: F401
import json
from pydantic import BaseModel, Field, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from pydantic import BaseModel, StrictInt, StrictStr, field_validator
from pydantic import Field
from openapi_client.models.category import Category
from openapi_client.models.tag import Tag
try:

View File

@@ -18,10 +18,8 @@ import pprint
import re # noqa: F401
import json
from pydantic import BaseModel, Field, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from pydantic import BaseModel, StrictInt, StrictStr, field_validator
from pydantic import Field
try:
from typing import Self
except ImportError:

View File

@@ -15,16 +15,8 @@
from __future__ import annotations
import json
import pprint
import re # noqa: F401
from enum import Enum
try:
from typing import Self
except ImportError:
from typing_extensions import Self
from typing_extensions import Self
class StringEnumRef(str, Enum):

View File

@@ -18,9 +18,8 @@ import pprint
import re # noqa: F401
import json
from typing import Any, ClassVar, Dict, List, Optional
from pydantic import BaseModel, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
try:
from typing import Self
except ImportError:

View File

@@ -18,9 +18,8 @@ import pprint
import re # noqa: F401
import json
from typing import Any, ClassVar, Dict, List, Optional
from pydantic import BaseModel, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
try:
from typing import Self
except ImportError:

View File

@@ -18,9 +18,8 @@ import pprint
import re # noqa: F401
import json
from typing import Any, ClassVar, Dict, List, Optional
from pydantic import BaseModel, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
try:
from typing import Self
except ImportError: