glyph, 6 months ago PEP 593 is a bit vague on how you’re supposed to actually consume arguments to Annotated; here is my proposal. https://blog.glyph.im/2023/12/annotated-at-runtime.html #python #programming #mypy
PEP 593 is a bit vague on how you’re supposed to actually consume arguments to Annotated; here is my proposal.
Annotated
https://blog.glyph.im/2023/12/annotated-at-runtime.html
#python #programming #mypy
mambocab, 6 months ago @glyph Thanks for the writeup. Small typo: > However, I think that this is a slightly misframing of the problem.
@glyph Thanks for the writeup. Small typo:
> However, I think that this is a slightly misframing of the problem.
glyph, 6 months ago @mambocab your attention to detail is much appreciated. Will fix
@mambocab your attention to detail is much appreciated. Will fix
glyph, 6 months ago @mambocab correction should be rolling out momentarily
@mambocab correction should be rolling out momentarily
elventear, 6 months ago @glyph coincidently I have been trying to implement a solution that uses information encoded in the Annotated arguments. Your code works great. One thing I have noticed is that mypy doesn’t seem to type check inside the Annotated declarations. Is that your experience as well?
@glyph coincidently I have been trying to implement a solution that uses information encoded in the Annotated arguments. Your code works great.
One thing I have noticed is that mypy doesn’t seem to type check inside the Annotated declarations. Is that your experience as well?
glyph, 6 months ago @elventear Huh. I haven't seen that yet. Probably worth reporting that as a bug though, that doesn't sound good
@elventear Huh. I haven't seen that yet. Probably worth reporting that as a bug though, that doesn't sound good
ubernostrum, 6 months ago @glyph Might also compare to how some of the type-hint-oriented frameworks do it. I believe this is Litestar's implementation here: https://github.com/litestar-org/litestar/blob/8f2cbe630ad9d71521f0477c6f0a3c0ed1c9a4a5/litestar/typing.py#L481
@glyph Might also compare to how some of the type-hint-oriented frameworks do it. I believe this is Litestar's implementation here:
https://github.com/litestar-org/litestar/blob/8f2cbe630ad9d71521f0477c6f0a3c0ed1c9a4a5/litestar/typing.py#L481
glyph, 6 months ago @ubernostrum yeah I linked to pydantic’s implementation and if anything litestar’s looks even jankier. That is a lot of Any
@ubernostrum yeah I linked to pydantic’s implementation and if anything litestar’s looks even jankier. That is a lot of Any
Any
jcristharif, 6 months ago @glyph @ubernostrum There are also a few other types-that-transparently-ish-wrap-other-types (Final, NewType, Annotated, TypeAlias) - properly traversing and stripping metadata from these is a pain. Due to <reasons>, I maintain two gross implementations of this code in msgspec - one in python (https://github.com/jcrist/msgspec/blob/ba316c44089104873da550700973845bddd167f5/msgspec/inspect.py#L611), and one in C (https://github.com/jcrist/msgspec/blob/ba316c44089104873da550700973845bddd167f5/msgspec/_core.c#L4384-L4398). My kingdom for cleaner (but still efficient) public APIs here.
@glyph @ubernostrum There are also a few other types-that-transparently-ish-wrap-other-types (Final, NewType, Annotated, TypeAlias) - properly traversing and stripping metadata from these is a pain.
Final
NewType
TypeAlias
Due to <reasons>, I maintain two gross implementations of this code in msgspec - one in python (https://github.com/jcrist/msgspec/blob/ba316c44089104873da550700973845bddd167f5/msgspec/inspect.py#L611), and one in C (https://github.com/jcrist/msgspec/blob/ba316c44089104873da550700973845bddd167f5/msgspec/_core.c#L4384-L4398). My kingdom for cleaner (but still efficient) public APIs here.
ubernostrum, 6 months ago @jcristharif @glyph My stance on type hints for a while now has been that: Many of the most interesting projects involving type hints are doing things with them at runtime, rather than static ahead-of-time checking, and The people writing type-hinting PEPs have seemed to be almost completely unaware of this. This discussion is an example of both of those points. (also, the fact that it was all about nominal typing for such a long time was annoying and kept me from really wanting to bother adopting)
@jcristharif @glyph My stance on type hints for a while now has been that:
This discussion is an example of both of those points.
(also, the fact that it was all about nominal typing for such a long time was annoying and kept me from really wanting to bother adopting)
Add comment