Skip to content

AttributeError if array type does not has items property #207

@zhustec

Description

@zhustec

https://github.com/phalt/clientele/blob/main/clientele/generators/standard/utils.py#L148-L150

    elif t_type == DataType.ARRAY:
        print(t, t_type, t.get("items"))
        inner_class = get_type(t.get("items"))
        base_type = f"list[{inner_class}]"

For array without items property:

{'type': 'array', 'items': {'type': 'number'}} array {'type': 'number'}
{'type': 'array'} array None

it throw an error:

  File "...\.venv\Lib\site-packages\clientele\generators\standard\utils.py", line 150, in get_type
    inner_class = get_type(t.get("items"))
  File "...\.venv\Lib\site-packages\clientele\generators\standard\utils.py", line 100, in get_type
    t_type = t.get("type")
             ^^^^^
AttributeError: 'NoneType' object has no attribute 'get'

one posible solution is set inner_class to typing.Any when t.get("items") is None

    elif t_type == DataType.ARRAY:
        inner_class = get_type(t.get("items")) if t.get("items") else "typing.Any"
        base_type = f"list[{inner_class}]"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions