This page documents the static analysis tools used to maintain code quality in the auth0-python SDK, including type checking with mypy and linting with ruff. For information about testing infrastructure, see Testing Infrastructure. For CI/CD integration of these tools, see CI/CD Pipeline.
The SDK employs two primary code quality tools configured in pyproject.toml1-102:
| Tool | Version | Primary Purpose |
|---|---|---|
mypy | 1.13.0 | Static type checking with Pydantic plugin support |
ruff | 0.11.5 | Fast linting and formatting (replaces black, flake8, isort, pyupgrade) |
Both tools are installed as development dependencies and configured to accommodate the dual architecture of the SDK: the modern type-safe Management API v5 and the legacy Authentication API.
Sources: pyproject.toml51-59 pyproject.toml70-101
Sources: pyproject.toml70-101
The mypy configuration is minimal but strategic, targeting only the code designed for type safety:
Sources: pyproject.toml70-73
The Management API v5 uses Pydantic models extensively for request/response validation. The pydantic.mypy plugin enhances type checking by:
__init__ signatures against model definitionsThis plugin is essential because the Management API codebase relies on Pydantic v1.9.2+ and pydantic-core 2.18.2+.
Sources: pyproject.toml71 pyproject.toml41-42
The Authentication API is explicitly excluded from type checking:
This exclusion exists because:
aiohttp and requests with different type signaturesThe Management API (src/auth0/management/) is fully type-checked, leveraging the Fern-generated OpenAPI types.
Sources: pyproject.toml72-73
ruff is configured to enforce consistent code style while accommodating necessary exceptions:
The tool consolidates functionality from multiple legacy tools (black, flake8, isort, pyupgrade) into a single fast Rust-based linter.
Sources: pyproject.toml75-83
Sources: pyproject.toml79-83
The configuration explicitly ignores certain rules to balance strictness with practical development needs:
| Rule | Category | Reason for Ignoring |
|---|---|---|
| E402 | Module import not at top | Allows conditional imports based on runtime checks |
| E501 | Line too long | Handled by line-length setting; some long strings unavoidable |
| E711 | Comparison to None | Legacy code uses == None patterns |
| E712 | Equality with True | Explicit boolean comparisons in some validation code |
| E721 | Type comparison style | Mixed use of type() and isinstance() |
| E722 | Bare except | Some legacy error handling uses bare except |
| E731 | Lambda assignment | Used in certain callback registration patterns |
| F821 | Undefined name | Forward references in type hints |
| F841 | Unused variable | Some fixture variables required by test framework |
Sources: pyproject.toml84-94
The isort functionality within ruff enforces import order:
This ensures consistent import organization:
from __future__ import ...)import json, import os)import httpx, import pydantic)from auth0.management import ...)Sources: pyproject.toml96-97
Both tools are specified as development dependencies with pinned versions:
Exact version pinning ensures:
Sources: pyproject.toml51-59
Sources: pyproject.toml38-65 .github/workflows/test.yml54-64
Developers run mypy locally to check type errors in the Management API:
The tool automatically:
[tool.mypy] in pyproject.toml70-73src/auth0/authentication/ directorySources: pyproject.toml70-73
Developers run ruff to check and fix code style issues:
The tool automatically:
[tool.ruff] in pyproject.toml75-97Sources: pyproject.toml75-97
The CI/CD pipeline (.github/workflows/test.yml1-85) currently does not enforce code quality tools as required checks. The workflow file contains commented-out lint checks:
This code represents the legacy tool stack that ruff now replaces.
Sources: .github/workflows/test.yml70-79
The repository has migrated from multiple tools to ruff:
| Old Tool | Purpose | Replacement |
|---|---|---|
| black 23.3.0 | Code formatting | ruff format |
| flake8 5.0.4 | Linting | ruff check (E, F rules) |
| isort 5.11.5 | Import sorting | ruff check (I rules) |
| pyupgrade 3.3.2 | Syntax modernization | Not directly replaced |
The migration to ruff provides:
Sources: .github/workflows/test.yml70-79 pyproject.toml59
Sources: pyproject.toml70-97
Located at pyproject.toml70-73:
pydantic.mypy for Pydantic v1/v2 compatibilitysrc/auth0/authentication/ directory completely skippedLocated at pyproject.toml75-97:
| Stage | Tool | Command | Purpose |
|---|---|---|---|
| Pre-commit | ruff | ruff check . --fix | Fix auto-fixable style issues |
| Pre-commit | ruff | ruff format . | Format code consistently |
| Pre-push | mypy | mypy | Verify Management API types |
| Pre-push | ruff | ruff check . | Final lint verification |
When mypy reports errors in Management API code:
isinstance() or type guards# type: ignore: Only as last resort for known false positivesWhen ruff reports errors:
ruff check . --fix to automatically resolve fixable issues# noqa: E711 for unavoidable violationsignore list if pattern is acceptableSources: pyproject.toml75-97
Refresh this wiki