Skip to content

Commit

Permalink
Fix NewType and NamedTuple (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
yeandy committed Sep 8, 2022
1 parent 3b0d9ea commit 2ec2483
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 1 addition & 2 deletions sdks/python/apache_beam/runners/interactive/sql/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ def pformat_namedtuple(schema: NamedTuple) -> str:
return '{}({})'.format(
schema.__name__,
', '.join([
'{}: {}'.format(k, v.__name__ if hasattr(v, '__name__') else repr(v))
for k,
'{}: {}'.format(k, repr(v)) for k,
v in schema.__annotations__.items()
]))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ def convert_to_beam_type(typ):
# TODO(https://github.com/apache/beam/issues/19954): Currently unhandled.
_LOGGER.info('Converting string literal type hint to Any: "%s"', typ)
return typehints.Any
elif sys.version_info >= (3, 10) and isinstance(typ, typing.NewType): # pylint: disable=isinstance-second-argument-not-valid-type
# Special case for NewType, where, since Python 3.10, NewType is now a class
# rather than a function.
# TODO(https://github.com/apache/beam/issues/20076): Currently unhandled.
_LOGGER.info('Converting NewType type hint to Any: "%s"', typ)
return typehints.Any
elif getattr(typ, '__module__', None) != 'typing':
# Only translate types from the typing module.
return typ
Expand Down

0 comments on commit 2ec2483

Please sign in to comment.