JordanMilne / Advocate

An SSRF-preventing wrapper around Python's requests library. Advocate is no longer maintained, please fork and rename if you would like to continue work on it.
Other
92 stars 17 forks source link

type hints #21

Open sbdchd opened 2 years ago

sbdchd commented 2 years ago

Requests itself has types in the typeshed: https://github.com/python/typeshed/tree/6e985ef3de3678676d753a1efbf45fd67095a3b2/stubs/requests/requests

so maybe advocate can piggyback off those somehow, but type hints would be nice for static typing

JordanMilne commented 2 years ago

Agreed, adding type hints would be nice, and easily doable for the Advocate-specific parts of the API. I don't know how it'd work for the more dynamic parts of the API, though, specifically the requests.get() / requests.post() / ... wrapper functions in api.py that take **kwargs. The underlying requests module could be anywhere from version 2.18.4 to current, and the type signatures of its functions may have changed between versions.

For the moment, if you need static typing around uses of advocate, it might make sense to switch to using a requests.Session() rather than using advocate's wrappers. You can session.mount() advocate's validating HTTP adapters onto a regular requests.Session() and it'll behave more or less the same as using advocate.Session().

sbdchd commented 2 years ago

Oh using the session subclass looks great, thank you!