Colin-b / httpx_auth

Authentication classes to be used with httpx
MIT License
114 stars 26 forks source link

Indicate package is typed per PEP 561 #46

Closed nymous closed 2 years ago

nymous commented 2 years ago

Marks the httpx_auth package as typed so typecheckers can use the annotations, with the Typing :: Typed PyPI classifier as a bonus ^^

How to test

In a new virtualenv, run pip install mypy git+https://github.com/nymous/httpx_auth.git@indicate-typed-package. Create the following main.py, then run mypy main.py

from httpx_auth import OAuth2AuthorizationCode

oauth_class = OAuth2AuthorizationCode('https://www.authorization.url', 'https://www.token.url')

reveal_type(oauth_class)

OAuth2AuthorizationCode(123)  # This will fail mypy

Result before:

main.py:1: error: Skipping analyzing "httpx_auth": module is installed, but missing library stubs or py.typed marker
main.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
main.py:5: note: Revealed type is "Any"
Found 1 error in 1 file (checked 1 source file)

Result after:

main.py:5: note: Revealed type is "httpx_auth.authentication.OAuth2AuthorizationCode"
main.py:7: error: Missing positional argument "token_url" in call to "OAuth2AuthorizationCode"
main.py:7: error: Argument 1 to "OAuth2AuthorizationCode" has incompatible type "int"; expected "str"
Found 2 errors in 1 file (checked 1 source file)

Note: this will fail if mypy is run with the --strict flag (and more precisely --no-implicit-reexport), another PR like Colin-b/pytest_httpx#57 will come later.

Fixes #43 (with inspiration from Colin-b/pytest_httpx#44 for the setup.py package_data and the changelog entry)

sonarcloud[bot] commented 2 years ago

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication