Union of types is not supported
xcarlosamm opened this issue · 4 comments
xcarlosamm commented
Checklist
- I have included information about relevant versions
- I have verified that the issue persists when using the
master
branch of Faust.
Steps to reproduce
The following model raises a NotImplementedError exception
from typing import Union, List
import faust
class Person(faust.Record):
emails: Union[str, List[str]]
Expected behavior
Declare fields with the union of types without exception
Actual behavior
An exception is raised
Full traceback
Traceback (most recent call last):
File "/venv/poc/lib/python3.8/site-packages/venusian/__init__.py", line 220, in scan
__import__(modname)
File "/mnt/c/projects/dedalowcoding-streams/myapp/models.py", line 14, in <module>
class Person(faust.Record):
File "/venv/poc/lib/python3.8/site-packages/faust/models/record.py", line 114, in __init_subclass__
super().__init_subclass__(
File "/venv/poc/lib/python3.8/site-packages/faust/models/base.py", line 296, in __init_subclass__
finalizer()
File "/venv/poc/lib/python3.8/site-packages/faust/models/base.py", line 374, in _init_subclass
options.descriptors = cls._contribute_field_descriptors(cls, options)
File "/venv/poc/lib/python3.8/site-packages/faust/models/record.py", line 285, in _contribute_field_descriptors
descr.on_model_attached()
File "/venv/poc/lib/python3.8/site-packages/faust/models/fields.py", line 172, in on_model_attached
self._to_python = self._compile_type_expression()
File "/venv/poc/lib/python3.8/site-packages/faust/models/fields.py", line 185, in _compile_type_expression
comprehension = expr.as_function(stacklevel=2)
File "/venv/poc/lib/python3.8/site-packages/faust/models/typing.py", line 676, in as_function
sourcecode = self.as_string(name=name, argument_name=argument_name)
File "/venv/poc/lib/python3.8/site-packages/faust/models/typing.py", line 693, in as_string
expression = self.as_comprehension(argument_name)
File "/venv/poc/lib/python3.8/site-packages/faust/models/typing.py", line 702, in as_comprehension
return self.build(Variable(argument_name), self.expr)
File "/venv/poc/lib/python3.8/site-packages/faust/models/typing.py", line 705, in build
return self._build_expression(var, *args)
File "/venv/poc/lib/python3.8/site-packages/faust/models/typing.py", line 710, in _build_expression
res = node.build(var, *type_info.args)
File "/venv/poc/lib/python3.8/site-packages/faust/models/typing.py", line 334, in build
raise NotImplementedError(f"Union of types {args!r} not supported")
NotImplementedError: Union of types (<class 'str'>, typing.List[str]) not supported
Versions
- Python version: 3.8.10
- Faust version: 0.10.0
- Operating system: Ubuntu 20.04
- Kafka version: 7.3.0 (Confluent docker)
wbarnha commented
This is a known issue, unfortunately. For now you'll need to use:
class Person(faust.Record):
emails: list
I'll review the current state of typing in Records and see if I can make something work.