-
-
Notifications
You must be signed in to change notification settings - Fork 113
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
Fix py37-38 structuring of mixed typing/regular generics #219
Conversation
Codecov Report
@@ Coverage Diff @@
## main #219 +/- ##
==========================================
- Coverage 98.34% 98.32% -0.02%
==========================================
Files 16 16
Lines 723 718 -5
==========================================
- Hits 711 706 -5
Misses 12 12
Continue to review full report at Codecov.
|
Is this ready for review? |
Hi @Tinche, made some dumb mistakes prior, but now, it is ready! :) |
The implementation looks good, it needs a changelog entry and possibly documentation updates. We already have a lot of Hypothesis tests though, I don't want to add new ones. What we should do is change the existing tests to test for these. I will push a branch with some modified tests you can rebase on and see what I mean. |
OK, I can make a changelog entry. Regarding the hypothesis tests, would it make sense to hide my added tests behind conditional skip - |
Here's the new branch: https://github.com/python-attrs/cattrs/tree/tin/new-tests If you look at the last commit, I added bare |
And also, that is for a separate issue, but docs for contributing are outdated - poetry does not support editable installs -
|
Ah, we were using the alpha release of Poetry 1.2 for a while, which does support this, but fell back to 1.1 for other reasons. |
Ok, checked the branch you posted, I will
|
Sounds good. I think I missed a few, like |
Ah, true, so will in the types you missed and $$$ |
Hey @Tinche, it's ready for review - I have added changelog entry, tests for Did I miss something? |
Well, it seems that tests uncovered another failing case: >>> import attrs
>>> import cattrs
>>> from typing import Tuple
>>> @attrs.define
... class A:
... a: Tuple = attrs.field(default=('', '', ''))
>>> cattrs.unstructure(x)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/libor/.virtualenvs/p38/lib/python3.8/site-packages/cattr/converters.py", line 197, in unstructure
return self._unstructure_func.dispatch(
File "/home/libor/.virtualenvs/p38/lib/python3.8/site-packages/cattr/dispatch.py", line 49, in _dispatch
return self._function_dispatch.dispatch(cl)
File "/home/libor/.virtualenvs/p38/lib/python3.8/site-packages/cattr/dispatch.py", line 126, in dispatch
return handler(typ)
File "/home/libor/.virtualenvs/p38/lib/python3.8/site-packages/cattr/converters.py", line 722, in gen_unstructure_attrs_fromdict
h = make_dict_unstructure_fn(
File "/home/libor/.virtualenvs/p38/lib/python3.8/site-packages/cattr/gen.py", line 125, in make_dict_unstructure_fn
handler = converter._unstructure_func.dispatch(t)
File "/home/libor/.virtualenvs/p38/lib/python3.8/site-packages/cattr/dispatch.py", line 49, in _dispatch
return self._function_dispatch.dispatch(cl)
File "/home/libor/.virtualenvs/p38/lib/python3.8/site-packages/cattr/dispatch.py", line 126, in dispatch
return handler(typ)
File "/home/libor/.virtualenvs/p38/lib/python3.8/site-packages/cattr/converters.py", line 754, in gen_unstructure_iterable
h = make_iterable_unstructure_fn(
File "/home/libor/.virtualenvs/p38/lib/python3.8/site-packages/cattr/gen.py", line 339, in make_iterable_unstructure_fn
type_arg = get_args(cl)[0]
IndexError: tuple index out of range |
Again, failed on py37/8, is OK on py39 (and pressumably py310) |
I have pushed 2 commits
What remains to be fixed are tests for roundtrips of un/struct of sets and frozen sets. I am out for today, will investigate later. Cheers, Libor |
Also, all the checks around the code for |
I'm gonna have to ask you to return the (https://docs.python.org/3/library/typing.html#typing.MutableSequence) |
Yes, got it, that's what I missed from the documentation. |
* Tuple.__args__ is equal to (), which is not covered by cases already listed
OK, now, it should be complete:
What do you think? @Tinche |
Looks great! I think the changelog format needs to be tweaked but I can do that myself. Thanks! |
Fixes #218
(EDIT 3.2.) I added tests describing the following behaviours:
dict
,frozenset
,list
,set
,tuple
typing.
upper-case generic with 1 type parameter, which can itself be a lower-case generic - this excludes sets and tupletyping.Tuple
with variadic lower-case genericsCheers,
Libor