Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Congrats on 1.0, this looks really interesting and I'd like to try it. Does ty have any story for Django / DRF yet? I rely on django-stubs and its mypy plugin for models and querysets, so I'm curious how ty handles that kind of dynamic behavior.
 help



We added builtin support for django fairly recently! You can read about it here: https://docs.astral.sh/ty/features/third-party/django/

Oh nice, didn't know that, thanks! Does it handle DRF too, or just Django itself? Haven't had a chance to read the docs yet.

I don't think we have any special handling of DRF (yet). It would be good to know exactly what you need there! Feel free to file an issue on GitHub :-)

Thanks for the quick answer! I'll write up what I'd need for DRF and open an issue.

Why should the type checker have to know anything about Django? What if I want to make a framework with the same shape? Do I submit a PR to Ty? One that I bet would be rejected because I didn't have any users yet? Users who won't come without type checking support?

This style of development is unfair to innovators and ossifies the ecosystem.


Ideally it shouldn't; I don't think anyone would argue otherwise.

But (1) django is older than Python's type system, so it uses some very dynamic patterns that are hard to express using Python types. And (2) it's very popular, which means both that lots of people want their type checker to do Something Useful™ with django code, and that it would be very difficult to retrofit django to use dynamic patterns that _are_ more compatible with the type system. That combination makes it worth our time to add specific custom support for it.

For your own future library, the hope is that the type system has become capable enough that you wouldn't _need_ custom type checker support. Things like `dataclass_transform` [1] were added specifically so that _all_ libraries could express these kinds of things in ways that are visible to the type checkers without custom support.

If you're doing something that still doesn't fit into what the typing system provides, then the Python typing community wants to learn about your use case so that we can see if we can extend the typing system even further to support it.

[1] https://typing.python.org/en/latest/spec/dataclasses.html


The Python typing community has known about the expressiveness problems for years. It's forward-only, has no HKTs, no type computation, no complement. I can't even do generic parameter list transforms.

All of these are known deficiencies. Everyone who brings them up is told to pound sand, their use cases deemed illegitimate. Might as well be GNOME.

It's fundamentally unfair that Django gets to use aspects of the language other tools can't, and one hard coded dataclass-style transform is inadequate.

So help me God, if I ever do another large scale Python project, then if these issues aren't fixed in typing, I will vendor and modify a type checker in the project itself and teach it my project's patterns directly. I will not twist and distort my design vision so it rhymes with dataclass.


I agree; we don't like this either. But there is no palatable short-term alternative. If we don't do it, then Django/pydantic/attrs users will just prefer other type checkers that do. The best long-term option is to make all of this expressible in the type system; there are proposals currently under consideration that will go a long way towards this.

Plugins do provide a more level playing field, and we aren't closed to the possibility of supporting them in future. But they come with a whole host of challenging technical problems, and we have a lot of other high-priority things to work on.


These proposals have stalled behind consensus hell for years. Enabling plugins would be a pragmatic option: you could even spell them as HKTs or something right in the source. Or you could enable private type system extensions.

I'm not sure about Django + Ty specifically, but some dependencies need a plugin because they're impossible to type annotate otherwise. For example, sqlalchemy + mypy

sqlalchemy is kind of the counterexample now. they deprecated the mypy plugin in 2.0 because the new typed models just work without it. what still needs special handling is the really dynamic stuff, like django's reverse relations or pydantic turning a string into a Path like in the post.

Exactly. Why are we baking support for this or that package to the core instead of enabling plugins or just making the type system more expressive?



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: