jawah / niquests

“Safest, Fastest, Easiest, and Most advanced” Python HTTP Client. Production Ready! Drop-in replacement for Requests. HTTP/1.1, HTTP/2, and HTTP/3 supported.
https://niquests.readthedocs.io/en/latest/
Apache License 2.0
811 stars 19 forks source link

Fix HttpAuthenticationType to add callable #133

Closed MtkN1 closed 3 months ago

MtkN1 commented 3 months ago

Add a callable object to the HttpAuthenticationType type definition.

A type checking error occurs when a callable object is given as the auth argument.

image

Reproduction code ```python import niquests def pizza_auth(request: niquests.PreparedRequest) -> niquests.PreparedRequest: if request.headers: request.headers["X-Pizza"] = "Token" return request def test_callable_auth(): r = niquests.get("https://httpbin.org/get", auth=pizza_auth) print(r.json()["headers"]) if __name__ == "__main__": test_callable_auth() ```

This is allowed at runtime.

https://github.com/jawah/niquests/blob/d83ab6b98e317bbf82ea950a693fce1fc95936a3/src/niquests/models.py#L615-L647