Merge stubs from djangorestframework-stubs into the codebase #7807
Replies: 9 comments
-
Hi. I think we need to double down on the discussion on Django here. It seems to me that it got stalled some time back, because typing wasn’t great, but that it’s come a long way since then, but the objections haven’t been addressed. More or less, if we can say Django is going to go for it then big yes to DRF. How does the discussion seem to you? |
Beta Was this translation helpful? Give feedback.
-
It got stuck on me writing a DEP=) Could we maybe iterate on it over email with you? It would be much more comfortable for me than writing it all at once. As for
django-stubs is somewhat popular, most features are covered. It's not a feat of improved |
Beta Was this translation helpful? Give feedback.
-
I've added a draft DEP/RFC for you and others to consider django/deps#65 |
Beta Was this translation helpful? Give feedback.
-
Hi @mkurnikov. I'm not that familiar with mypy since I've never been a fan of the type annotation syntax. However, the concept of stub files is new to me and seems interesting. Is the idea that we'd be adding these stub files to DRF, or is the expectation that we'd inline type annotations? I guess my questions are:
And if it's not too much effort (and I mean very low effort, don't want to waste your time if this isn't going anywhere), could you throw together a preliminary PR? I'm thinking:
|
Beta Was this translation helpful? Give feedback.
-
AFAIK, if stubs are in the same repo, they should be in the same directory, near the original file. But if they're going to remain in the stubs, they might as well just remain in the different package, like currently in
In the current state of mypy, there's no way to use stubs to typecheck code itself. My proposal to make it inline originated from this exact problem, There's a tools like
Most effort would be in tox, I never worked with it, but I'll try. Annotations are no-brainer, there's already done for most of the files, I'll just copy-paste them from |
Beta Was this translation helpful? Give feedback.
-
Well, it might be easier to keep them up-to-date if they were located in the DRF repo, but again, I'm not sure what the maintenance process is like so ¯\_(ツ)_/¯
tox is a great tool and I highly recommend learning it irrespective of this PR. Regardless, you're most likely going to want to do something that mimics the Lines 46 to 51 in 0fd72f1 |
Beta Was this translation helpful? Give feedback.
-
So, firstly - I took a look over the stub package, and I'm actually really impressed. Big chunk of work there, and looks nicer than expected. Saying that I probably wouldn't want us to include stubs. If we're going to include typing information then it ought to be in the codebase itself. I'm not totally convinced that DRF is a great target for adding typing information - I find type checking really useful in projects where it's enabled from the start, and is part of the CI process, ensuring that it's consistent when used. It's less clear that it'd be valuable when backporting it to an existing large project which already has decent coverage, and very mature years-long exposure. |
Beta Was this translation helpful? Give feedback.
-
@tomchristie
for example. Also, if codebase is typechecked (= mypy aware of the types), there's possibility to add more capabilities with a plugin for mypy. UPD. Typechecking of |
Beta Was this translation helpful? Give feedback.
-
Here's the PR: #6988 |
Beta Was this translation helpful? Give feedback.
-
Hi, I'm the primary maintainer of https://github.com/typeddjango/djangorestframework-stubs and https://github.com/typeddjango/django-stubs
As Python 2 support is dropped, would you be open to merging mentioned stubs into the codebase?
I can make a PR with the change, if it will be accepted. I can also help with a mypy plugin to return a proper
TypedDict
from theserializer.data
attribute, based on defined fieldshttps://www.python.org/dev/peps/pep-0589/
Beta Was this translation helpful? Give feedback.
All reactions