Skip to content

Commit 63d0bd7

Browse files
committed
parser / properties / avoid call to isinstance for perf imprv
1 parent f1cdd88 commit 63d0bd7

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

openapi_python_client/parser/properties/__init__.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"property_from_data",
1010
]
1111

12+
from itertools import chain
1213
from typing import Any, ClassVar, Dict, Generic, Iterable, Iterator, List, Optional, Set, Tuple, TypeVar, Union
1314

1415
import attr
@@ -352,12 +353,7 @@ def build_union_property(
352353
) -> Tuple[Union[UnionProperty, PropertyError], Schemas]:
353354
sub_properties: List[Property] = []
354355

355-
sub_data: List[Union[oai.Schema, oai.Reference]] = []
356-
for _data in [data.anyOf, data.oneOf]:
357-
if isinstance(_data, Iterable):
358-
sub_data.extend(_data)
359-
360-
for i, sub_prop_data in enumerate(sub_data):
356+
for i, sub_prop_data in enumerate(chain(data.anyOf or [], data.oneOf or [])):
361357
sub_prop, schemas = property_from_data(
362358
name=f"{name}_type{i}",
363359
required=required,
@@ -445,8 +441,8 @@ def _property_from_data(
445441
return _property_from_ref(name=name, required=required, parent=None, data=data, schemas=schemas)
446442

447443
sub_data: List[Union[oai.Schema, oai.Reference]] = []
448-
for _data in [data.allOf, data.anyOf, data.oneOf]:
449-
if isinstance(_data, Iterable):
444+
for _data in (data.allOf, data.anyOf, data.oneOf):
445+
if _data:
450446
sub_data.extend(_data)
451447

452448
# A union of a single reference should just be passed through to that reference (don't create copy class)

0 commit comments

Comments
 (0)