Colin-b / httpx_auth

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

Explicit reexports to appease `mypy --strict` and pyright #47

Closed nymous closed 2 years ago

nymous commented 2 years ago

Explicitly export in __all__ all imports in __init__.py, so that mypy --strict and pyright are happy.

How to test

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

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: Module "httpx_auth" does not explicitly export attribute "OAuth2AuthorizationCode"; implicit reexport disabled
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 branch is based on indicate-typed-package, because it doesn't affect anything if the package isn't marked as typed. Tell me if I should base it off develop instead.

Fixes #43 (with inspiration from Colin-b/pytest_httpx#57 for 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