-
-
Notifications
You must be signed in to change notification settings - Fork 454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Recent changes to test.client.Client.get() do not accept valid data types #1327
Comments
Most likely caused by #1297, pinging @nils-van-zuijlen |
I know this works. But these values will be converted to a URL query string and thus stringified anyway. It won't retain the original bool data type after deserialization (unlike for example JSON). So passing booleans or ints into query params seems just sloppy. Personally I prefer my type stubs to be stricter, even if it means I have to adapt my code and make a few changes here and there. The adaptation is straightforward, just quote the boolean value: Do you see any downsides doing this? Any third opinions? |
As the author of this type annotation, I am aware it is not perfect. It was mentioned in the PR that ints should be allowed because there are unit tests in Django that use ints, and I fully agree that it is a useful pattern (having a parameterized test that loops through a range). Int parameters are annotated in the django-rest-framework sister PR typeddjango/djangorestframework-stubs#267 I personally don't think booleans should be allowed because there is no normalized way to represent them in urls. (to mind comes The question becomes, do we want to annotate with all working types, or with only the types that make sense? |
Yeah, that got omitted from the django-stubs one. I think since Python's As stated, my slight preference is not to allow them. But I don't have strong feelings either way. What's more important is that we are consistent between django-stubs and djangorestframework-stubs. |
Another point is that this only affects test code. I guess it's fine to prioritize convenience over strictness in tests. |
Fair enough. My feeling was that if Django expects and handles the types, then the type hints should allow for it. |
To clarify by "Another point" I meant as a point to allow @nils-van-zuijlen as the author of these, I'll leave the final decision up to you. |
int and bool will be accepted, after PR #1345. |
Bug report
What's wrong
test.client.Client.get()
expects thedata
arg to beMapping[str, str | bytes | Iterable[str | bytes]] | Iterable[tuple[str, str | bytes | Iterable[str | bytes]]] | None
but the method works with other options as well such as when the value is a bool. ie.self.client.get(url, data={'somevar': True}
How is that should be
get() data with a bool value should be accepted.
Here is an example from the codebase in question
This works with django-stubs 1.13.1, but fails with 1.13.1 and 1.13.2 even though self.client.get() works as expected and translates the python True and False correctly.
System information
python
version: 3.11.1django
version: 4.1.5mypy
version: 0.991django-stubs
version: 1.13.2django-stubs-ext
version: 0.7.0The text was updated successfully, but these errors were encountered: