This is an automated email from the ASF dual-hosted git repository.
damccorm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git
The following commit(s) were added to refs/heads/master by this push:
new 4eefc6dd544 Apply changes (#30857)
4eefc6dd544 is described below
commit 4eefc6dd5445b982082aa329527e3e86b547e86a
Author: Hai Joey Tran <[email protected]>
AuthorDate: Fri Apr 5 08:07:57 2024 -0400
Apply changes (#30857)
---
sdks/python/apache_beam/coders/coders.py | 10 +++++++---
sdks/python/apache_beam/coders/coders_test.py | 6 ++++++
2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/sdks/python/apache_beam/coders/coders.py
b/sdks/python/apache_beam/coders/coders.py
index d5e717d7b9c..a0c55da8180 100644
--- a/sdks/python/apache_beam/coders/coders.py
+++ b/sdks/python/apache_beam/coders/coders.py
@@ -242,9 +242,10 @@ class Coder(object):
return self.__dict__
def to_type_hint(self):
- raise NotImplementedError(
- 'https://github.com/apache/beam/issues/18490: %s' %
- self.__class__.__name__)
+ # TODO: After https://github.com/apache/beam/issues/18490 we should be
+ # able to infer the type hint rather than require every subclass define
+ # it
+ raise NotImplementedError
@classmethod
def from_type_hint(cls, unused_typehint, unused_registry):
@@ -1482,6 +1483,9 @@ class LengthPrefixCoder(FastCoder):
def __hash__(self):
return hash((type(self), self._value_coder))
+ def to_type_hint(length_prefix_coder):
+ return length_prefix_coder.value_coder().to_type_hint()
+
Coder.register_structured_urn(
common_urns.coders.LENGTH_PREFIX.urn, LengthPrefixCoder)
diff --git a/sdks/python/apache_beam/coders/coders_test.py
b/sdks/python/apache_beam/coders/coders_test.py
index 1143e9c5d87..4d8e8fe9bcb 100644
--- a/sdks/python/apache_beam/coders/coders_test.py
+++ b/sdks/python/apache_beam/coders/coders_test.py
@@ -236,6 +236,12 @@ class NullableCoderTest(unittest.TestCase):
nondeterministic.as_deterministic_coder('label')
+class LengthPrefixCoderTest(unittest.TestCase):
+ def test_to_type_hint(self):
+ coder = coders.LengthPrefixCoder(coders.BytesCoder())
+ assert coder.to_type_hint() is bytes
+
+
if __name__ == '__main__':
logging.getLogger().setLevel(logging.INFO)
unittest.main()