|
| 1 | +[mypy] |
| 2 | +# ============================================================================== |
| 3 | +# Global mypy Configuration |
| 4 | +# ============================================================================== |
| 5 | +# Python version: Specifies the target Python version for type checking. |
| 6 | +# This ensures compatibility with the specified Python version's type system. |
| 7 | +python_version = 3.11 |
| 8 | + |
| 9 | +# Strict mode: Enables all strict type checking options for maximum type safety. |
| 10 | +# This is recommended for production code to catch potential type-related bugs early. |
| 11 | +strict = True |
| 12 | + |
| 13 | +# Exclusion patterns: Directories to exclude from type checking. |
| 14 | +# - tests: Test files often have different type checking requirements |
| 15 | +# - migrations: Database migration scripts typically don't benefit from type checking |
| 16 | +# - docs: Documentation code examples don't need strict type checking |
| 17 | +# - .venv: Virtual environment files should never be type checked |
| 18 | +exclude = (?x)( |
| 19 | + ^tests/ |
| 20 | + | ^migrations/ |
| 21 | + | ^docs/ |
| 22 | + | .venv/ |
| 23 | + ) |
| 24 | + |
| 25 | +# Source directory: Sets the base directory for import resolution. |
| 26 | +# This helps mypy correctly resolve imports within your project structure. |
| 27 | +mypy_path = src |
| 28 | + |
| 29 | +# Namespace packages: Enables support for PEP 420 namespace packages. |
| 30 | +# Useful for projects with a distributed package structure across multiple directories. |
| 31 | +namespace_packages = True |
| 32 | + |
| 33 | +# Explicit package bases: Ensures clear package structure with defined base directories. |
| 34 | +# Helps prevent import confusion in complex project structures. |
| 35 | +explicit_package_bases = True |
| 36 | + |
| 37 | +# ============================================================================== |
| 38 | +# Plugin Configuration |
| 39 | +# ============================================================================== |
| 40 | +# Mypy plugins: Extends mypy's type checking capabilities for specific libraries. |
| 41 | +# - pydantic.mypy: Adds support for Pydantic model type checking |
| 42 | +# - sqlalchemy.ext.mypy.plugin: Enhances SQLAlchemy ORM type checking |
| 43 | +plugins = |
| 44 | + pydantic.mypy, |
| 45 | + sqlalchemy.ext.mypy.plugin |
| 46 | + |
| 47 | +# ============================================================================== |
| 48 | +# Strict Type Checking Settings |
| 49 | +# ============================================================================== |
| 50 | +# Function definitions: Requires explicit type annotations for all function definitions. |
| 51 | +# This ensures that function signatures are clear and well-documented. |
| 52 | +disallow_untyped_defs = True |
| 53 | + |
| 54 | +# Incomplete definitions: Prohibits functions with partial type annotations. |
| 55 | +# Ensures consistency by requiring complete type information for all parameters and returns. |
| 56 | +disallow_incomplete_defs = True |
| 57 | + |
| 58 | +# Untyped function checking: Enables type checking for functions without annotations. |
| 59 | +# Helps catch type errors even in functions that haven't been properly annotated yet. |
| 60 | +check_untyped_defs = True |
| 61 | + |
| 62 | +# Decorator annotations: Requires type annotations for decorators. |
| 63 | +# Important for ensuring type safety when using custom decorators. |
| 64 | +disallow_untyped_decorators = True |
| 65 | + |
| 66 | +# Implicit Optional handling: Disables automatic Optional typing for parameters with None defaults. |
| 67 | +# Forces explicit declaration of Optional types for better code clarity. |
| 68 | +no_implicit_optional = True |
| 69 | + |
| 70 | +# Redundant cast warnings: Flags unnecessary type casts to improve code cleanliness. |
| 71 | +# Helps maintain clean code by removing unnecessary type casting operations. |
| 72 | +warn_redundant_casts = True |
| 73 | + |
| 74 | +# Unused ignore warnings: Flags unnecessary # type: ignore comments. |
| 75 | +# Prevents accumulation of outdated type-ignore directives in the codebase. |
| 76 | +warn_unused_ignores = True |
| 77 | + |
| 78 | +# Missing return warnings: Warns about functions that don't return a value but should. |
| 79 | +# Catches potential bugs where a function is expected to return a value. |
| 80 | +warn_no_return = True |
| 81 | + |
| 82 | +# Unreachable code: Warns about code that can never be executed. |
| 83 | +# Identifies dead code that should be removed for maintenance clarity. |
| 84 | +warn_unreachable = True |
| 85 | + |
| 86 | +# Optional type checking: Enables strict checking of Optional types. |
| 87 | +# Ensures proper handling of potentially None values throughout the codebase. |
| 88 | +strict_optional = True |
| 89 | + |
| 90 | +# Equality checking: Ensures proper equality checks between different types. |
| 91 | +# Prevents subtle bugs from comparing incompatible types. |
| 92 | +strict_equality = True |
| 93 | + |
| 94 | +# Sequence concatenation: Enforces proper type checking when concatenating sequences. |
| 95 | +# Prevents type errors when combining lists, tuples, or other sequence types. |
| 96 | +strict_concatenate = True |
| 97 | + |
| 98 | +# ============================================================================== |
| 99 | +# Additional Production Safety Checks |
| 100 | +# ============================================================================== |
| 101 | +# Enhanced error detection: Enables specific error codes for production code safety. |
| 102 | +# These additional checks help catch subtle bugs that might otherwise go unnoticed. |
| 103 | +enable_error_code = [ |
| 104 | + "truthy-bool", # Prevents using non-boolean expressions in boolean contexts (if x: vs if x is True:) |
| 105 | + "redundant-expr", # Identifies expressions that have no effect and can be removed |
| 106 | + "unused-awaitable", # Catches forgotten await statements that could lead to unexpected behavior |
| 107 | + "ignore-without-code", # Requires specific error codes with # type: ignore for better documentation |
| 108 | + "possibly-undefined", # Identifies variables that might be undefined in some execution paths |
| 109 | + "redundant-self", # Flags unnecessary self or cls parameters in methods |
| 110 | +] |
| 111 | + |
| 112 | +# ============================================================================== |
| 113 | +# Error Reporting Configuration |
| 114 | +# ============================================================================== |
| 115 | +# Output formatting: Configures how mypy presents error messages for better usability. |
| 116 | +# These settings make error messages more readable and actionable. |
| 117 | +pretty = True # Uses a more readable format for error messages |
| 118 | +show_error_context = True # Displays the code context where errors occur |
| 119 | +show_column_numbers = True # Shows precise column positions for errors |
| 120 | +show_error_codes = True # Includes error codes for easier reference and suppression |
| 121 | +color_output = True # Uses colors in terminal output for better readability |
| 122 | +error_summary = True # Provides a summary of all errors at the end of the report |
| 123 | + |
| 124 | +# ============================================================================== |
| 125 | +# Import Discovery Configuration |
| 126 | +# ============================================================================== |
| 127 | +# Import handling: Controls how mypy processes and validates imports. |
| 128 | +# These settings determine how strictly mypy enforces type checking for imported modules. |
| 129 | +ignore_missing_imports = False # By default, requires type stubs for all imports |
| 130 | +follow_imports = normal # Normal import following behavior for type checking |
| 131 | +follow_imports_for_stubs = True # Prioritizes type stubs over implementation modules |
| 132 | + |
| 133 | +# ============================================================================== |
| 134 | +# Third-party Library Configurations |
| 135 | +# ============================================================================== |
| 136 | +# Library-specific settings: Configures type checking behavior for external dependencies. |
| 137 | +# Libraries without complete type annotations need special handling to prevent false positives. |
| 138 | +[mypy-orjson.*] |
| 139 | +ignore_missing_imports = True # Skips import verification for this library |
| 140 | +ignore_errors = true # Ignores type errors within this library's code |
| 141 | + |
| 142 | +[mypy-dotenv.*] |
| 143 | +ignore_missing_imports = True # Skips import verification for this library |
| 144 | +ignore_errors = true # Ignores type errors within this library's code |
| 145 | + |
| 146 | +# ============================================================================== |
| 147 | +# Database-related Configurations |
| 148 | +# ============================================================================== |
| 149 | +# ORM and database connectors: Special handling for database interaction libraries. |
| 150 | +# These libraries often use dynamic attribute access that's difficult to type check. |
| 151 | +[mypy-sqlalchemy.*] |
| 152 | +ignore_missing_imports = True # SQLAlchemy uses complex metaprogramming that's hard to type check |
| 153 | + |
| 154 | +[mypy-alembic.*] |
| 155 | +ignore_missing_imports = True # Alembic migration tool lacks complete type annotations |
| 156 | + |
| 157 | +[mypy-asyncpg.*] |
| 158 | +ignore_missing_imports = True # AsyncPG PostgreSQL client lacks complete type annotations |
| 159 | + |
| 160 | +[mypy-databases.*] |
| 161 | +ignore_missing_imports = True # Databases library lacks complete type annotations |
| 162 | + |
| 163 | +# ============================================================================== |
| 164 | +# Web Framework Configurations |
| 165 | +# ============================================================================== |
| 166 | +# FastAPI and ASGI: Configuration for web framework components. |
| 167 | +# Web frameworks often use complex dependency injection and routing that needs special handling. |
| 168 | +[mypy-fastapi.*] |
| 169 | +ignore_missing_imports = True # FastAPI uses Pydantic models and complex routing |
| 170 | + |
| 171 | +[mypy-starlette.*] |
| 172 | +ignore_missing_imports = True # Starlette (FastAPI foundation) lacks complete type annotations |
| 173 | + |
| 174 | +[mypy-uvicorn.*] |
| 175 | +ignore_missing_imports = True # ASGI server lacks complete type annotations |
| 176 | + |
| 177 | +[mypy-gunicorn.*] |
| 178 | +ignore_missing_imports = True # WSGI HTTP server lacks complete type annotations |
| 179 | + |
| 180 | +# ============================================================================== |
| 181 | +# HTTP Clients and Related Libraries |
| 182 | +# ============================================================================== |
| 183 | +# HTTP client libraries: Configuration for making network requests. |
| 184 | +# These libraries often have complex async patterns or dynamic response handling. |
| 185 | +[mypy-httpx.*] |
| 186 | +ignore_missing_imports = True # Modern async HTTP client |
| 187 | + |
| 188 | +[mypy-requests.*] |
| 189 | +ignore_missing_imports = True # Popular synchronous HTTP client |
| 190 | + |
| 191 | +[mypy-aiohttp.*] |
| 192 | +ignore_missing_imports = True # Async HTTP client and server framework |
| 193 | + |
| 194 | +# ============================================================================== |
| 195 | +# Serialization/Validation Configurations |
| 196 | +# ============================================================================== |
| 197 | +# Data validation libraries: Settings for data parsing and validation tools. |
| 198 | +# These libraries often use complex validation logic and dynamic field access. |
| 199 | +[mypy-pydantic.*] |
| 200 | +ignore_missing_imports = True # Data validation using Python type annotations |
| 201 | + |
| 202 | +[mypy-pydantic_settings.*] |
| 203 | +ignore_missing_imports = True # Settings management with Pydantic |
| 204 | + |
| 205 | +[mypy-email_validator.*] |
| 206 | +ignore_missing_imports = True # Email validation library used by Pydantic |
| 207 | + |
| 208 | +# ============================================================================== |
| 209 | +# Testing Frameworks |
| 210 | +# ============================================================================== |
| 211 | +# Test libraries: Configuration for testing tools and frameworks. |
| 212 | +# Testing libraries use fixtures and assertions that can be complex to type check. |
| 213 | +[mypy-pytest.*] |
| 214 | +ignore_missing_imports = True # Popular Python testing framework |
| 215 | + |
| 216 | +[mypy-hypothesis.*] |
| 217 | +ignore_missing_imports = True # Property-based testing framework |
| 218 | + |
| 219 | +# ============================================================================== |
| 220 | +# Utility Libraries |
| 221 | +# ============================================================================== |
| 222 | +# Common utilities: Settings for general-purpose utility libraries. |
| 223 | +# These provide infrastructure components that may use dynamic patterns. |
| 224 | +[mypy-celery.*] |
| 225 | +ignore_missing_imports = True # Distributed task queue |
| 226 | + |
| 227 | +[mypy-redis.*] |
| 228 | +ignore_missing_imports = True # Redis client library |
| 229 | + |
| 230 | +# ============================================================================== |
| 231 | +# Type Checking Adjustments for ORM Patterns |
| 232 | +# ============================================================================== |
| 233 | +# ORM compatibility: Relaxes certain type checks that conflict with ORM patterns. |
| 234 | +# These adjustments allow for common ORM usage patterns while maintaining type safety. |
| 235 | +allow_any_generics = True # Allows Any in generic types (needed for some ORM patterns) |
| 236 | +allow_redefinition = True # Permits redefinition of names in certain contexts |
| 237 | + |
| 238 | +# Disables specific error codes that often conflict with ORM and framework patterns |
| 239 | +disable_error_code = [ |
| 240 | + "override", # Allows method overrides with signature differences (common in framework extensions) |
| 241 | + "empty-body", # Permits empty function bodies (useful for abstract methods and protocol definitions) |
| 242 | + "misc", # Disables miscellaneous checks that may be too strict for framework integration |
| 243 | + "arg-type", # Relaxes argument type checking for legacy code and framework callbacks |
| 244 | +] |
| 245 | + |
| 246 | +# ============================================================================== |
| 247 | +# Framework-specific Error Ignores |
| 248 | +# ============================================================================== |
| 249 | +# Special cases: Ignores errors in specific framework modules with complex metaprogramming. |
| 250 | +# These modules use advanced Python features that are difficult for static type checkers. |
| 251 | +[mypy-fastapi.dependencies.utils] |
| 252 | +ignore_errors = True # FastAPI dependency resolution uses complex metaprogramming |
| 253 | + |
| 254 | +[mypy-fastapi.routing] |
| 255 | +ignore_errors = True # FastAPI routing system uses decorators and complex type patterns |
| 256 | + |
| 257 | +[mypy-sqlalchemy.orm.decl_api] |
| 258 | +ignore_errors = True # SQLAlchemy declarative API uses metaclasses and dynamic attributes |
| 259 | + |
| 260 | +# ============================================================================== |
| 261 | +# Cache Backends |
| 262 | +# ============================================================================== |
| 263 | +# Caching libraries: Configuration for memory and distributed cache systems. |
| 264 | +# These libraries often use dynamic key/value access patterns. |
| 265 | +[mypy-cachetools.*] |
| 266 | +ignore_missing_imports = True # In-memory caching utilities |
| 267 | + |
| 268 | +[mypy-aiocache.*] |
| 269 | +ignore_missing_imports = True # Async caching framework |
| 270 | + |
| 271 | +# ============================================================================== |
| 272 | +# Background Tasks and Scheduling |
| 273 | +# ============================================================================== |
| 274 | +# Task processing: Settings for background job processing libraries. |
| 275 | +# These systems often use decorators and dynamic task registration. |
| 276 | +[mypy-apscheduler.*] |
| 277 | +ignore_missing_imports = True # Advanced Python scheduler |
| 278 | + |
| 279 | +[mypy-dramatiq.*] |
| 280 | +ignore_missing_imports = True # Background task processing system |
0 commit comments