diff --git a/sdks/python/apache_beam/runners/interactive/sql/utils.py b/sdks/python/apache_beam/runners/interactive/sql/utils.py index 471240ee7b566..1be17f2c911ae 100644 --- a/sdks/python/apache_beam/runners/interactive/sql/utils.py +++ b/sdks/python/apache_beam/runners/interactive/sql/utils.py @@ -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() ])) diff --git a/sdks/python/apache_beam/typehints/native_type_compatibility.py b/sdks/python/apache_beam/typehints/native_type_compatibility.py index 4be0b30e7c998..2a54450e212a7 100644 --- a/sdks/python/apache_beam/typehints/native_type_compatibility.py +++ b/sdks/python/apache_beam/typehints/native_type_compatibility.py @@ -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