Skip to content

Commit

Permalink
fix exit code and write extract types using yield
Browse files Browse the repository at this point in the history
  • Loading branch information
cakemanny committed Feb 20, 2024
1 parent bfbb702 commit 9f6c58b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
17 changes: 8 additions & 9 deletions fastclasses_json/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,24 +505,23 @@ def referenced_types(cls):
def extract_types(t):
origin = typing_get_origin(t)
if origin == tuple and typing_get_args(t):
xs = tuple()
for type_arg in typing_get_args(t):
xs += extract_types(type_arg)
return xs
if (origin == typing.Union
yield from extract_types(type_arg)
elif (origin == typing.Union
or issubclass_safe(origin, abc.Sequence)) and typing_get_args(t):
type_arg = typing_get_args(t)[0]
return extract_types(type_arg)
yield from extract_types(type_arg)
elif issubclass_safe(origin, abc.Mapping) and typing_get_args(t):
key_type_arg, value_type_arg = typing_get_args(t)
if key_type_arg is UUID:
return (UUID,) + extract_types(value_type_arg)
return extract_types(value_type_arg)
yield UUID
yield from extract_types(value_type_arg)
elif is_dataclass(t) or issubclass_safe(
t, (Enum, date, datetime, Decimal, UUID)
):
return (t,)
return tuple()
yield t
else:
yield from tuple()

types = {}
for _, field_type in typing.get_type_hints(cls).items():
Expand Down
2 changes: 1 addition & 1 deletion scripts/version_changelog
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ParseError(Exception):
def print_usage_and_exit(exit_code=1):
out = sys.stdout if exit_code == 0 else sys.stderr
print(f"{sys.argv[0]} <new version>", file=out)
exit(1)
exit(exit_code)


def parse_version(line):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Intended Audience :: Developers",
"Development Status :: 3 - Alpha",
"Development Status :: 4 - Beta",
],
)

0 comments on commit 9f6c58b

Please sign in to comment.