|
24 | 24 | import unittest |
25 | 25 |
|
26 | 26 | import apache_beam as beam |
| 27 | +from apache_beam.options.pipeline_options import PipelineOptions |
| 28 | +from apache_beam.options.pipeline_options_context import scoped_pipeline_options |
27 | 29 | from apache_beam.typehints import row_type |
28 | 30 | from apache_beam.typehints import trivial_inference |
29 | 31 | from apache_beam.typehints import typehints |
@@ -489,15 +491,28 @@ def testPyCallable(self): |
489 | 491 | [int]) |
490 | 492 |
|
491 | 493 | def testDataClassFields(self): |
| 494 | + @dataclasses.dataclass |
| 495 | + class BaseClass: |
| 496 | + pass |
| 497 | + |
492 | 498 | @dataclasses.dataclass |
493 | 499 | class MyDataClass: |
494 | 500 | id: int |
495 | 501 | name: str |
| 502 | + tags: list[str] |
| 503 | + custom: BaseClass |
496 | 504 |
|
497 | 505 | self.assertReturnType( |
498 | | - typehints.Tuple[int, str], |
499 | | - python_callable.PythonCallableWithSource("lambda x: (x.id, x.name)"), |
500 | | - [MyDataClass]) |
| 506 | + typehints.Tuple[int, str, typehints.List[str], BaseClass], |
| 507 | + python_callable.PythonCallableWithSource( |
| 508 | + "lambda x: (x.id, x.name, x.tags, x.custom)"), [MyDataClass]) |
| 509 | + |
| 510 | + options = PipelineOptions(['--exclude_infer_dataclass_field_type']) |
| 511 | + with scoped_pipeline_options(options): |
| 512 | + self.assertReturnType( |
| 513 | + typehints.Tuple[int, str, typehints.Any, typehints.Any], |
| 514 | + python_callable.PythonCallableWithSource( |
| 515 | + "lambda x: (x.id, x.name, x.tags, x.custom)"), [MyDataClass]) |
501 | 516 |
|
502 | 517 |
|
503 | 518 | if __name__ == '__main__': |
|
0 commit comments