Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
I think this is fixable by deferring the signature inspection into the inside of the GenericCallable. That's what I was getting at earlier Though there might still be snags going the other direction |
|
@msullivan I'm not sure that's possible during runtime. It's possible at type check time at least, but if I try to look at the annotations of something like |
Right, we'll need to do it inside the Kind of a pain; not the highest priority I suppose |
msullivan
left a comment
There was a problem hiding this comment.
- Did you test adding methods?
- Does
format_classstill work with__init_subclass__or is that the end of the world
| if ( | ||
| (init_subclass := base.__dict__.get("__init_subclass__")) | ||
| and ( | ||
| init_subclass_annos := getattr( | ||
| init_subclass, "__annotations__", None | ||
| ) | ||
| ) | ||
| and (ret_annotation := init_subclass_annos.get("return")) | ||
| ): |
There was a problem hiding this comment.
Instead of grabbing __annotations__ directly, we should call __annotate__ with a special environment, like we do elsewhere. That way we can arrange to put the correct type variable in at the start, and have it evaluate correctly.
... maybe; there are still snags in other places, and I'm not 100% sure we can overcome them.
There was a problem hiding this comment.
That could be a follow-up though
| # An annoying thing to know is that for a member classmethod of C, | ||
| # cls *should* be type[C], but if it was not explicitly annotated, | ||
| # it will be C. |
There was a problem hiding this comment.
I don't totally follow this?
There was a problem hiding this comment.
I was also confused. I have a followup that will make things more straightforward.
|
Added some tests for adding callables. The format class stuff worked, it was just kind of annoying to keep in sync as I was tweaking things. I've added them back in. |
Lets us write things like:
B.nwill be interpretted asset[int]Note: There is an unfortunate part of python in general, where we must wrap any for/if statements in annotations in a generic type alias.