New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing types with custom class deserializers #167
Comments
Thanks for reporting! Will take a look! |
hmm I got the different error 🤔 Traceback (most recent call last):
File "/Users/yukinari/repos/pyserde/examples/a.py", line 13, in <module>
class CustomDe:
File "/Users/yukinari/Library/Caches/pypoetry/virtualenvs/pyserde-examples-eLlM1BJJ-py3.9/lib/python3.9/site-packages/serde/de.py", line 196, in wrap
add_func(scope, FROM_ITER, render_from_iter(cls, deserializer), g)
File "/Users/yukinari/Library/Caches/pypoetry/virtualenvs/pyserde-examples-eLlM1BJJ-py3.9/lib/python3.9/site-packages/serde/de.py", line 689, in render_from_iter
return env.get_template('iter').render(func=FROM_ITER, serde_scope=getattr(cls, SERDE_SCOPE), fields=defields(cls))
File "/Users/yukinari/Library/Caches/pypoetry/virtualenvs/pyserde-examples-eLlM1BJJ-py3.9/lib/python3.9/site-packages/jinja2/environment.py", line 1304, in render
self.environment.handle_exception()
File "/Users/yukinari/Library/Caches/pypoetry/virtualenvs/pyserde-examples-eLlM1BJJ-py3.9/lib/python3.9/site-packages/jinja2/environment.py", line 925, in handle_exception
raise rewrite_traceback_stack(source=source)
File "<template>", line 16, in top-level template code
File "/Users/yukinari/Library/Caches/pypoetry/virtualenvs/pyserde-examples-eLlM1BJJ-py3.9/lib/python3.9/site-packages/serde/de.py", line 479, in render
f'serde_custom_class_deserializer({arg.type.__name__}, {arg.datavar}, {arg.data}, '
File "/opt/homebrew/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/typing.py", line 701, in __getattr__
raise AttributeError(attr)
AttributeError: __name__ |
Interesting. The output in my original-comment is from a Python 3.10 venv. Notably, I can use With a Python 3.9 venv, I get the exact same error you do. Since it fails sooner, |
OK, it reproduced with a small fix. |
I think #169 fixed the issue. Could you please verify? |
Yes, it now works for me. Thanks! |
Great! Thanks! |
The code generation doesn't put
Optional
orUnion
in scope when calling a custom class deserializer. This results in aNameError
during deserialization.Example
Output
The text was updated successfully, but these errors were encountered: