|
1 | 1 | # Pyrefly configuration schema |
2 | | -# Based on CLI options documented in PYREFLY_GUIDE.md |
3 | | -# Note: Pyrefly configuration is still evolving, this is a minimal implementation |
| 2 | +# Based on official Pyrefly documentation: https://pyrefly.org/en/docs/configuration/ |
| 3 | +# CLI reference: https://github.com/facebook/pyrefly |
| 4 | +# |
| 5 | +# Note: Field names use snake_case (Python convention) but are automatically |
| 6 | +# converted to kebab-case when written to pyrefly.toml (official format). |
4 | 7 |
|
5 | 8 | from __future__ import annotations |
6 | 9 |
|
|
9 | 12 | # Basic configuration options based on Pyrefly CLI |
10 | 13 | IndexingMode = Literal["none", "lazy-non-blocking-background", "lazy-blocking"] |
11 | 14 |
|
| 15 | +# Type checking behavior options |
| 16 | +UntypedDefBehavior = Literal[ |
| 17 | + "check-and-infer-return-type", |
| 18 | + "check-and-infer-return-any", |
| 19 | + "skip-and-infer-return-any", |
| 20 | +] |
| 21 | + |
| 22 | +# Error severity configuration (error-code -> enabled/disabled) |
| 23 | +ErrorConfig = dict[str, bool] |
| 24 | + |
12 | 25 |
|
13 | 26 | class Model(TypedDict): |
14 | 27 | """ |
15 | 28 | Pyrefly Configuration Schema |
16 | 29 |
|
17 | | - Based on available CLI options and environment variables. |
18 | | - Note: Pyrefly's configuration format is still evolving. |
| 30 | + Comprehensive type definitions for all Pyrefly configuration options. |
| 31 | + Field names use snake_case following Python conventions. Pyrefly accepts |
| 32 | + both snake_case and kebab-case in TOML configuration files. |
| 33 | +
|
| 34 | + All fields are NotRequired for maximum flexibility. For arbitrary fields |
| 35 | + not yet in this schema: |
| 36 | + - Use cast(dict, config) to add extra keys |
| 37 | + - Or pass plain dict to write_config (accepts Mapping[str, Any]) |
| 38 | +
|
| 39 | + Official Documentation: https://pyrefly.org/en/docs/configuration/ |
19 | 40 | """ |
20 | 41 |
|
21 | | - # Core options |
| 42 | + # ======================================================================== |
| 43 | + # CORE OPTIONS (CLI-compatible) |
| 44 | + # ======================================================================== |
| 45 | + |
22 | 46 | verbose: NotRequired[bool] |
23 | | - threads: NotRequired[int] # 0 = auto, 1 = sequential, higher = parallel |
| 47 | + """Enable detailed logging output""" |
| 48 | + |
| 49 | + threads: NotRequired[int] |
| 50 | + """Thread count (0=auto, 1=sequential, >1=parallel)""" |
| 51 | + |
24 | 52 | color: NotRequired[Literal["auto", "always", "never"]] |
| 53 | + """Control colored output in terminal""" |
| 54 | + |
| 55 | + # ======================================================================== |
| 56 | + # LSP SERVER OPTIONS |
| 57 | + # ======================================================================== |
| 58 | + |
| 59 | + indexing_mode: NotRequired[IndexingMode] |
| 60 | + """Indexing strategy for LSP server (default: lazy-non-blocking-background)""" |
| 61 | + |
| 62 | + disable_type_errors_in_ide: NotRequired[bool] |
| 63 | + """Hide type errors when running in IDE/language server mode""" |
| 64 | + |
| 65 | + # ======================================================================== |
| 66 | + # FILE SELECTION |
| 67 | + # ======================================================================== |
| 68 | + |
| 69 | + project_includes: NotRequired[list[str]] |
| 70 | + """Glob patterns for files to type check (default: ["**/*.py*"])""" |
| 71 | + |
| 72 | + project_excludes: NotRequired[list[str]] |
| 73 | + """Glob patterns to exclude from type checking""" |
| 74 | + |
| 75 | + disable_project_excludes_heuristics: NotRequired[bool] |
| 76 | + """Disable automatic exclusion patterns (allows custom specification)""" |
| 77 | + |
| 78 | + use_ignore_files: NotRequired[bool] |
| 79 | + """Use .gitignore, .ignore, .git/info/exclude for exclusions (default: true)""" |
| 80 | + |
| 81 | + # ======================================================================== |
| 82 | + # PYTHON ENVIRONMENT (User-requested: search_path, python_version) |
| 83 | + # ======================================================================== |
| 84 | + |
| 85 | + search_path: NotRequired[list[str]] |
| 86 | + """Directories where imports are resolved from (USER REQUESTED)""" |
| 87 | + |
| 88 | + disable_search_path_heuristics: NotRequired[bool] |
| 89 | + """Prevent automatic search path detection""" |
| 90 | + |
| 91 | + site_package_path: NotRequired[list[str]] |
| 92 | + """Third-party package directories for import resolution""" |
| 93 | + |
| 94 | + python_version: NotRequired[str] |
| 95 | + """Python version for sys.version checks, e.g. "3.13.0" (USER REQUESTED)""" |
| 96 | + |
| 97 | + python_platform: NotRequired[str] |
| 98 | + """Platform for sys.platform checks, e.g. "linux", "darwin", "win32" """ |
| 99 | + |
| 100 | + conda_environment: NotRequired[str] |
| 101 | + """Conda environment name for querying Python configuration""" |
| 102 | + |
| 103 | + python_interpreter_path: NotRequired[str] |
| 104 | + """Path to Python executable for environment detection""" |
| 105 | + |
| 106 | + fallback_python_interpreter_name: NotRequired[str] |
| 107 | + """Interpreter name on $PATH for automatic discovery (default: "python3")""" |
| 108 | + |
| 109 | + skip_interpreter_query: NotRequired[bool] |
| 110 | + """Skip querying Python interpreter for environment setup""" |
| 111 | + |
| 112 | + # ======================================================================== |
| 113 | + # TYPE CHECKING BEHAVIOR |
| 114 | + # ======================================================================== |
| 115 | + |
| 116 | + typeshed_path: NotRequired[str] |
| 117 | + """Override bundled typeshed with custom path""" |
| 118 | + |
| 119 | + untyped_def_behavior: NotRequired[UntypedDefBehavior] |
| 120 | + """How to handle untyped function definitions (default: check-and-infer-return-type)""" |
| 121 | + |
| 122 | + infer_with_first_use: NotRequired[bool] |
| 123 | + """Infer container types from first usage patterns (default: true)""" |
| 124 | + |
| 125 | + ignore_errors_in_generated_code: NotRequired[bool] |
| 126 | + """Skip type checking for files containing @generated marker""" |
| 127 | + |
| 128 | + permissive_ignores: NotRequired[bool] |
| 129 | + """Respect ignore annotations from non-Pyrefly tools (e.g. # type: ignore)""" |
| 130 | + |
| 131 | + enabled_ignores: NotRequired[list[str]] |
| 132 | + """Tool ignore directives to recognize (default: ["type", "pyrefly"])""" |
| 133 | + |
| 134 | + # ======================================================================== |
| 135 | + # IMPORT HANDLING |
| 136 | + # ======================================================================== |
| 137 | + |
| 138 | + replace_imports_with_any: NotRequired[list[str]] |
| 139 | + """Module globs to unconditionally replace with typing.Any""" |
| 140 | + |
| 141 | + ignore_missing_imports: NotRequired[list[str]] |
| 142 | + """Module globs to replace with typing.Any when not found""" |
25 | 143 |
|
26 | | - # LSP server options |
27 | | - indexing_mode: NotRequired[IndexingMode] # Indexing strategy for LSP server |
| 144 | + ignore_missing_source: NotRequired[bool] |
| 145 | + """Ignore missing source packages when only type stubs are available""" |
28 | 146 |
|
29 | | - # File inclusion/exclusion (basic patterns) |
30 | | - include: NotRequired[list[str]] |
31 | | - exclude: NotRequired[list[str]] |
| 147 | + # ======================================================================== |
| 148 | + # ERROR CONFIGURATION |
| 149 | + # ======================================================================== |
32 | 150 |
|
33 | | - # Environment variables that can be configured |
34 | | - pyrefly_threads: NotRequired[int] |
35 | | - pyrefly_color: NotRequired[str] |
36 | | - pyrefly_verbose: NotRequired[bool] |
| 151 | + errors: NotRequired[ErrorConfig] |
| 152 | + """Error severity configuration: {"error-code": bool, ...}""" |
0 commit comments