Skip to content

Stubs for requests are too restrictive #1093

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

Closed
gvanrossum opened this issue Mar 25, 2017 · 6 comments
Closed

Stubs for requests are too restrictive #1093

gvanrossum opened this issue Mar 25, 2017 · 6 comments
Labels
stubs: incomplete Annotations or sub-modules missing from an existing package or module

Comments

@gvanrossum
Copy link
Member

The 3rd party requests library is too dynamic for static typing, and its maintainers don't care about static typing. (There was previous discussion about this; can someone look up the issue?)

We still have stubs to guide users away from the most egregious issues, but the stubs are too restrictive. Maybe we should be satisfied with all methods and functions being(*args: Any, **kwds: Any) -> Any?

@gvanrossum
Copy link
Member Author

At the same time they are incomplete, some submodules (e.g. packages) have no stubs at all, and that causes errors in mypy despite --ignore-missing-modules.

@OJFord
Copy link
Contributor

OJFord commented Nov 25, 2017

There's also an issue using requests.codes, e.g. codes.accepted will cause mypy to complain that:

error: "LookupDict" has no attribute "accepted"

This is true enough, but requests.structures.LookupDict hacks __getitem__ to allow it; it's much cleaner than codes['accepted'], and idiomatic as far as I'm aware.

(Aside: the reason code names are not actually defined is that in some cases there are a few aliases, and presumably the authors preferred to list aliases once in a 'lookup dict' than to def them all.)

@gvanrossum
Copy link
Member Author

Is this a limited set of attributes? Because then we can just add them all to the stub.

@OJFord
Copy link
Contributor

OJFord commented Nov 25, 2017

Yes, but it is quite big. (A laborious rather than complex task.) Here's an excerpt:

https://github.com/requests/requests/blob/19919b44c4af95f125704c902acecdf83d70a3e4/requests/status_codes.py#L54-L61

Edit: Or not an excerpt then - apparently code previews don't work across repos.

@gvanrossum
Copy link
Member Author

gvanrossum commented Nov 25, 2017 via email

@srittau srittau added size-large stubs: incomplete Annotations or sub-modules missing from an existing package or module labels Oct 21, 2018
@hauntsaninja
Copy link
Collaborator

This issue is pretty stale; several improvements have been made to requests' stubs and it's used enough that most egregious false positives are probably fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stubs: incomplete Annotations or sub-modules missing from an existing package or module
Projects
None yet
Development

No branches or pull requests

4 participants