-
-
Notifications
You must be signed in to change notification settings - Fork 118
Structuring Generics #52
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
Comments
Hi, this is very interesting but I'm a little sick at the moment so it might take me a while to take a look. Thanks! |
@Tinche have you had any time to take a look at this? I have been playing around with it a bunch more and cleared out all of the issues that I have run into and can say it makes me love cattrs even more. I have started to use it in some of my smaller systems to try and get some load against it and see if I have find any more problems. I can tell you being able to replace custom and nested deserializer with typing is about as good as it gets for me.. |
This had made it into our production environment for over 6 months now and things have been pretty stable so far. Going to be merging in the last changes to support python3.8 in the next couple days. If this is something that is of interest, I will happily put in the work to merge #51. If not I can release my own forked library but would like to work towards getting this merged in here. |
I am currently running into the same issue and I am wondering how to tackle structuring and unstructuring of generics... |
I should have closed this off once the PR was merged. structuring generics just works now. https://github.com./Tinche/cattrs/blob/master/tests/test_generics.py Here are some unit tests with it, I am going to close out my old ticket. I would open a new one if you are still having issues. |
I realized I forgot to file an issue before submitting a PR, but this is to capture #51 .
The problem I have experienced is complex object with generic can be tedious to make work. Take the below code as an example, to use cattrs I need to register a hook for type
~T
which in this case would be assign it toint
, or I could register a hook onM
.If a TypeVar with the name
T
is used anywhere else in my code it must be of type int or structuring is going to have issues.; This gets even worse when you have nested generics that share the same type var name. I typically just use T more my generic variable name, so I run into this problem often.To address this, what I would like to see cattrs support is passing a
_GenericAlias
into the structure function and automatically handle the structuring if possible. The code above would stay the same except the last line which would becomeGiven this support, I no longer need to manually register
~T
or M and the existing structuring mechanisms could be utilized to handle the structuring. The mentioned PR is my first pass at implementing this feature, looking to see if this i something the library is willing support before I continue the work in polishing the code, documentation and tests.The text was updated successfully, but these errors were encountered: