Skip to content

Commit

Permalink
python: Remove usage of six (OpenAPITools#16675)
Browse files Browse the repository at this point in the history
  • Loading branch information
akx authored and AlanCitrix committed Oct 26, 2023
1 parent 11def4e commit 874d817
Show file tree
Hide file tree
Showing 31 changed files with 30 additions and 58 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import connexion
import six

{{#imports}}{{import}} # noqa: E501
{{/imports}}
Expand Down Expand Up @@ -94,15 +93,15 @@ def {{operationId}}({{#allParams}}{{paramName}}{{^required}}=None{{/required}}{{
{{#items}}
{{#isDate}}
if connexion.request.is_json:
{{paramName}} = {k: util.deserialize_date(v) for k, v in six.iteritems(connexion.request.get_json())} # noqa: E501
{{paramName}} = {k: util.deserialize_date(v) for k, v in connexion.request.get_json().items()} # noqa: E501
{{/isDate}}
{{#isDateTime}}
if connexion.request.is_json:
{{paramName}} = {k: util.deserialize_datetime(v) for k, v in six.iteritems(connexion.request.get_json())} # noqa: E501
{{paramName}} = {k: util.deserialize_datetime(v) for k, v in connexion.request.get_json().items()} # noqa: E501
{{/isDateTime}}
{{#complexType}}
if connexion.request.is_json:
{{paramName}} = {k: {{baseType}}.from_dict(v) for k, v in six.iteritems(connexion.request.get_json())} # noqa: E501
{{paramName}} = {k: {{baseType}}.from_dict(v) for k, v in connexion.request.get_json().items()} # noqa: E501
{{/complexType}}
{{/items}}
{{/isMap}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from connexion.apps.flask_app import FlaskJSONEncoder
import six

from {{modelPackage}}.base_model import Model

Expand All @@ -10,7 +9,7 @@ class JSONEncoder(FlaskJSONEncoder):
def default(self, o):
if isinstance(o, Model):
dikt = {}
for attr, _ in six.iteritems(o.swagger_types):
for attr in o.swagger_types:
value = getattr(o, attr)
if value is None and not self.include_nulls:
continue
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import pprint

import six
import typing

from {{packageName}} import util
Expand Down Expand Up @@ -29,7 +28,7 @@ class Model(object):
"""
result = {}

for attr, _ in six.iteritems(self.swagger_types):
for attr in self.swagger_types:
value = getattr(self, attr)
if isinstance(value, list):
result[attr] = list(map(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from __future__ import absolute_import

from flask import json
from six import BytesIO
from io import BytesIO

{{#imports}}{{import}} # noqa: E501
{{/imports}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import datetime

import six
import typing
from {{packageName}} import typing_utils

Expand All @@ -16,7 +15,7 @@ def _deserialize(data, klass):
if data is None:
return None

if klass in six.integer_types or klass in (float, str, bool):
if klass == int or klass in (float, str, bool):
return _deserialize_primitive(data, klass)
elif klass == object:
return _deserialize_object(data)
Expand Down Expand Up @@ -45,7 +44,7 @@ def _deserialize_primitive(data, klass):
try:
value = klass(data)
except UnicodeEncodeError:
value = six.u(data)
value = str(data)
except TypeError:
value = data
return value
Expand Down Expand Up @@ -104,7 +103,7 @@ def deserialize_model(data, klass):
if not instance.swagger_types:
return data

for attr, attr_type in six.iteritems(instance.swagger_types):
for attr, attr_type in instance.swagger_types.items():
if data is not None \
and instance.attribute_map[attr] in data \
and isinstance(data, (list, dict)):
Expand Down Expand Up @@ -139,4 +138,4 @@ def _deserialize_dict(data, boxed_type):
:rtype: dict
"""
return {k: _deserialize(v, boxed_type)
for k, v in six.iteritems(data)}
for k, v in data.items()}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ python-multipart==0.0.5
PyYAML==5.4.1
requests==2.25.1
Rx==1.6.1
six==1.16.0
starlette==0.27.0
typing-extensions==3.10.0.0
ujson==4.0.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@

import re # noqa: F401

# python 2 and python 3 compatibility library
import six

from petstore_api.api_client import ApiClient
from petstore_api.exceptions import ( # noqa: F401
ApiTypeError,
Expand Down Expand Up @@ -119,7 +116,7 @@ def test_classname_with_http_info(self, client, **kwargs): # noqa: E501
]
)

for key, val in six.iteritems(local_var_params['kwargs']):
for key, val in local_var_params['kwargs'].items():
if key not in all_params:
raise ApiTypeError(
"Got an unexpected keyword argument '%s'"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"""

import os
import six
import sys
import unittest

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"""

import os
import six
import sys
import unittest

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@

import re # noqa: F401

# python 2 and python 3 compatibility library
import six

from petstore_api.api_client import ApiClient
from petstore_api.exceptions import ( # noqa: F401
ApiTypeError,
Expand Down Expand Up @@ -119,7 +116,7 @@ def test_classname_with_http_info(self, client, **kwargs): # noqa: E501
]
)

for key, val in six.iteritems(local_var_params['kwargs']):
for key, val in local_var_params['kwargs'].items():
if key not in all_params:
raise ApiTypeError(
"Got an unexpected keyword argument '%s'"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"""

import os
import six
import sys
import unittest

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"""

import os
import six
import sys
import unittest

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import connexion
import six
from typing import Dict
from typing import Tuple
from typing import Union
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import connexion
import six
from typing import Dict
from typing import Tuple
from typing import Union
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import connexion
import six
from typing import Dict
from typing import Tuple
from typing import Union
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from connexion.apps.flask_app import FlaskJSONEncoder
import six

from openapi_server.models.base_model import Model

Expand All @@ -10,7 +9,7 @@ class JSONEncoder(FlaskJSONEncoder):
def default(self, o):
if isinstance(o, Model):
dikt = {}
for attr, _ in six.iteritems(o.openapi_types):
for attr in o.openapi_types:
value = getattr(o, attr)
if value is None and not self.include_nulls:
continue
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import pprint

import six
import typing

from openapi_server import util
Expand Down Expand Up @@ -29,7 +28,7 @@ def to_dict(self):
"""
result = {}

for attr, _ in six.iteritems(self.openapi_types):
for attr in self.openapi_types:
value = getattr(self, attr)
if isinstance(value, list):
result[attr] = list(map(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import unittest

from flask import json
from six import BytesIO
from io import BytesIO

from openapi_server.models.api_response import ApiResponse # noqa: E501
from openapi_server.models.pet import Pet # noqa: E501
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import unittest

from flask import json
from six import BytesIO
from io import BytesIO

from openapi_server.models.order import Order # noqa: E501
from openapi_server.test import BaseTestCase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import unittest

from flask import json
from six import BytesIO
from io import BytesIO

from openapi_server.models.user import User # noqa: E501
from openapi_server.test import BaseTestCase
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import datetime

import six
import typing
from openapi_server import typing_utils

Expand All @@ -16,7 +15,7 @@ def _deserialize(data, klass):
if data is None:
return None

if klass in six.integer_types or klass in (float, str, bool, bytearray):
if klass == int or klass in (float, str, bool, bytearray):
return _deserialize_primitive(data, klass)
elif klass == object:
return _deserialize_object(data)
Expand Down Expand Up @@ -45,7 +44,7 @@ def _deserialize_primitive(data, klass):
try:
value = klass(data)
except UnicodeEncodeError:
value = six.u(data)
value = str(data)
except TypeError:
value = data
return value
Expand Down Expand Up @@ -110,7 +109,7 @@ def deserialize_model(data, klass):
if not instance.openapi_types:
return data

for attr, attr_type in six.iteritems(instance.openapi_types):
for attr, attr_type in instance.openapi_types.items():
if data is not None \
and instance.attribute_map[attr] in data \
and isinstance(data, (list, dict)):
Expand Down Expand Up @@ -145,4 +144,4 @@ def _deserialize_dict(data, boxed_type):
:rtype: dict
"""
return {k: _deserialize(v, boxed_type)
for k, v in six.iteritems(data)}
for k, v in data.items()}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import connexion
import six

from app.openapi_server.models.api_response import ApiResponse # noqa: E501
from app.openapi_server.models.pet import Pet # noqa: E501
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import connexion
import six

from app.openapi_server.models.order import Order # noqa: E501
from openapi_server import util
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import connexion
import six

from app.openapi_server.models.user import User # noqa: E501
from openapi_server import util
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from connexion.apps.flask_app import FlaskJSONEncoder
import six

from app.openapi_server.models.base_model import Model

Expand All @@ -10,7 +9,7 @@ class JSONEncoder(FlaskJSONEncoder):
def default(self, o):
if isinstance(o, Model):
dikt = {}
for attr, _ in six.iteritems(o.swagger_types):
for attr in o.swagger_types:
value = getattr(o, attr)
if value is None and not self.include_nulls:
continue
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import pprint

import six
import typing

from openapi_server import util
Expand Down Expand Up @@ -29,7 +28,7 @@ def to_dict(self):
"""
result = {}

for attr, _ in six.iteritems(self.swagger_types):
for attr in self.swagger_types:
value = getattr(self, attr)
if isinstance(value, list):
result[attr] = list(map(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from __future__ import absolute_import

from flask import json
from six import BytesIO
from io import BytesIO

from app.openapi_server.models.api_response import ApiResponse # noqa: E501
from app.openapi_server.models.pet import Pet # noqa: E501
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from __future__ import absolute_import

from flask import json
from six import BytesIO
from io import BytesIO

from app.openapi_server.models.order import Order # noqa: E501
from openapi_server.test import BaseTestCase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from __future__ import absolute_import

from flask import json
from six import BytesIO
from io import BytesIO

from app.openapi_server.models.user import User # noqa: E501
from openapi_server.test import BaseTestCase
Expand Down
Loading

0 comments on commit 874d817

Please sign in to comment.