Okay. Does the PEP call that out in it’s specification? On Mon, Jan 25, 2021 at 17:33 Tin Tvrtković <tinchester@gmail.com> wrote:
As in TypeVars? It'd blow up. We need concrete types on this layer.
On Tue, Jan 26, 2021 at 2:23 AM Guido van Rossum <guido@python.org> wrote:
No video please! :-)
I see what your code does, in introspects tuple[int, int, int] (the dispatch mechanism isn't super important).
But what if the type is tuple[T, T, T]?
On Mon, Jan 25, 2021 at 5:09 PM Tin Tvrtković <tinchester@gmail.com> wrote:
Alright.
Let's assume you have a 3.9 virtualenv with cattrs installed.
from cattr import structure structure(["1", 1.0, True], tuple[int, int, int]) (1, 1, 1)
1. We run the value `tuple[int, int, int]` through the dispatch mechanism. It matches on this function: https://github.com/Tinche/cattrs/blob/e54fa1713b39fa3c944415bbe61aabd7e8bb42..., which ends up invoking this handler: https://github.com/Tinche/cattrs/blob/e54fa1713b39fa3c944415bbe61aabd7e8bb42... .
2. This handler fishes out the tuple type arguments, and it basically returns `tuple(cattr.structure(obj[0], int), cattr.structure(obj[1], int), cattr.structure(obj[2], int))`.
3. All three of these structure calls end up matching at https://github.com/Tinche/cattrs/blob/master/src/cattr/converters.py#L131, which points to https://github.com/Tinche/cattrs/blob/e54fa1713b39fa3c944415bbe61aabd7e8bb42..., which basically does int(x).
The top level call basically evaluates to `tuple(int(x[0]), int(x[1]), int(x[2]))`. This same mechanism supports other primitives, lists, dicts, sets, frozensets, optionals, enums, attrs classes, unions of attrs classes (with some restrictions) out of the box.
I feel if you'd like a more thorough walkthrough a video call would be better.
On Tue, Jan 26, 2021 at 1:52 AM Guido van Rossum <guido@python.org> wrote:
I really want to understand what you're doing to compute the results at runtime -- the PEP is already full of example signatures.
On Mon, Jan 25, 2021 at 4:10 PM Tin Tvrtković <tinchester@gmail.com> wrote:
Ok, sure. Are you looking for usage examples or me running through how the code works internally?
On Tue, Jan 26, 2021 at 12:08 AM Guido van Rossum <guido@python.org> wrote:
Could you construct some small(ish) examples and paste them here? I am still having a hard time imagining how you implement this at runtime.
-- --Guido van Rossum (python.org/~guido) *Pronouns: he/him **(why is my pronoun here?)* <http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/>
-- --Guido van Rossum (python.org/~guido) *Pronouns: he/him **(why is my pronoun here?)* <http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/>
-- --Guido (mobile)