Skip to content

Commit

Permalink
fix: Get type names in a py<310 compatible manner
Browse files Browse the repository at this point in the history
  • Loading branch information
effigies committed Sep 1, 2024
1 parent 684e753 commit 21cf04c
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/bids_validator/context_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ def typespec_to_type(name: str, typespec: Dict[str, Any]):
return type_, metadata


def _type_name(tp: type) -> str:
try:
return tp.__name__
except AttributeError:
return str(tp)


def create_attrs_class(
class_name: str,
properties: Dict[str, Any],
Expand Down Expand Up @@ -128,7 +135,12 @@ def create_attrs_class(
Attributes
----------
"""
+ '\n'.join([f'{k}: {v.type.__name__}' for k, v in attributes.items()]),
+ '\n'.join(
[
f'{k}: {_type_name(v.type)}\n\t{v.metadata["description"]}'
for k, v in attributes.items()
]
),
},
)

Expand Down

0 comments on commit 21cf04c

Please sign in to comment.