-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Support per-module strict config #20514
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1397,21 +1397,15 @@ def process_options( | |
| parser.error(f"Cannot find config file '{config_file}'") | ||
|
|
||
| options = Options() | ||
| strict_option_set = False | ||
|
|
||
| def set_strict_flags() -> None: | ||
| nonlocal strict_option_set | ||
| strict_option_set = True | ||
| for dest, value in strict_flag_assignments: | ||
| setattr(options, dest, value) | ||
|
|
||
| # Parse config file first, so command line can override. | ||
| parse_config_file(options, set_strict_flags, config_file, stdout, stderr) | ||
| parse_config_file(options, strict_flag_assignments, config_file, stdout, stderr) | ||
|
|
||
| # Set strict flags before parsing (if strict mode enabled), so other command | ||
| # line options can override. | ||
| if getattr(dummy, "special-opts:strict"): | ||
| set_strict_flags() | ||
| for dest, value in strict_flag_assignments: | ||
| setattr(options, dest, value) | ||
|
|
||
| # Override cache_dir if provided in the environment | ||
| environ_cache_dir = os.getenv("MYPY_CACHE_DIR", "") | ||
|
|
@@ -1529,9 +1523,6 @@ def set_strict_flags() -> None: | |
| if options.logical_deps: | ||
| options.cache_fine_grained = True | ||
|
|
||
| if options.strict_concatenate and not strict_option_set: | ||
| print("Warning: --strict-concatenate is deprecated; use --extra-checks instead") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change looks unrelated, why is it needed? |
||
|
|
||
| # Set target. | ||
| if special_opts.modules + special_opts.packages: | ||
| options.build_type = BuildType.MODULE | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -238,7 +238,7 @@ def __init__(self) -> None: | |
| # Disable treating bytearray and memoryview as subtypes of bytes | ||
| self.strict_bytes = False | ||
|
|
||
| # Deprecated, use extra_checks instead. | ||
| # Make arguments prepended via Concatenate be truly positional-only. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above, looks unrelated. |
||
| self.strict_concatenate = False | ||
|
|
||
| # Enable additional checks that are technically correct but impractical. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2152,6 +2152,56 @@ disallow_subclassing_any = true | |
| module = 'm' | ||
| disallow_subclassing_any = false | ||
|
|
||
| [case testStrictPerModule] | ||
| # flags: --config-file tmp/mypy.ini | ||
|
|
||
| import strictmodule | ||
| import loosemodule | ||
| a = 0 # type: ignore | ||
|
|
||
| [file strictmodule.py] | ||
| def foo(): # E: Function is missing a return type annotation \ | ||
| # N: Use "-> None" if function does not return a value | ||
| 1 + "asdf" # E: Unsupported operand types for + ("int" and "str") | ||
|
|
||
| a = 0 # type: ignore # E: Unused "type: ignore" comment | ||
|
|
||
|
|
||
| [file loosemodule.py] | ||
| def foo(): | ||
| 1 + "asdf" | ||
|
|
||
| a = 0 # type: ignore | ||
| 1 + "asdf" # E: Unsupported operand types for + ("int" and "str") | ||
|
|
||
| [file mypy.ini] | ||
| \[mypy] | ||
| strict = False | ||
| \[mypy-strictmodule] | ||
| strict = True | ||
|
|
||
|
|
||
| [case testStrictPerModuleOverride] | ||
| # flags: --config-file tmp/mypy.ini | ||
|
|
||
| import strictmodule | ||
| import strictermodule | ||
|
|
||
| [file strictmodule.py] | ||
| x: list | ||
| 0 # type: ignore | ||
|
|
||
| [file strictermodule.py] | ||
| x: list # E: Missing type arguments for generic type "list" | ||
| 0 # type: ignore # E: Unused "type: ignore" comment | ||
|
|
||
| [file mypy.ini] | ||
| \[mypy] | ||
| disallow_any_generics = false | ||
| strict = true | ||
| warn_unused_ignores = false | ||
| \[mypy-strictermodule] | ||
| strict = true | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure I like this semantics, but also not against it. In any case, precedence w.r.t individual flags in current and top-level configs should be clearly documented. |
||
|
|
||
| [case testNoImplicitOptionalPerModule] | ||
| # flags: --config-file tmp/mypy.ini | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what is the point of using
k in {"strict"}instead ofk == "strict".