Skip to content
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

Support module-level strict config flag #12174

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

icgood
Copy link

@icgood icgood commented Feb 14, 2022

Description

The current behavior of strict = True in a module-level config section actually enables all strictness flags globally, which seems like a bug. This change changes a module-level strict = True option to act as though all of the per-module strictness flags were enabled.

Test Plan

In addition to adding a basic unit test (the strict flag is hard to test since it is essentially a macro flag) I tested manually using a config file like this:

[mypy]
strict = True
[mypy-foo.*]
strict = False

I then confirmed that strictness flags were applied to non-foo packages (I removed some type hints and saw an error) and that strictness was not applied to the foo package (removed some type hints and saw no errors).

Personally I expected the strict config flag to behave this way already, so I don't think a change to the docs is needed.

The current behavior of `strict = True` in a module-level config section
actually enables all strictness flags globally, which seems like a bug.
This change changes a module-level `strict = True` option to act as
though all of the per-module strictness flags were enabled.
@github-actions

This comment has been minimized.

@@ -205,14 +207,17 @@ def parse_config_file(options: Options, set_strict_flags: Callable[[], None],
os.environ['MYPY_CONFIG_FILE_DIR'] = os.path.dirname(
os.path.abspath(config_file))

set_strict_flags_toplevel = partial(set_strict_flags, True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can create a real function instead? 🤔

Copy link
Author

@icgood icgood Feb 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just pushed a small refactor using inline functions with a stronger unit test.

@icgood
Copy link
Author

icgood commented Feb 14, 2022

FYI the CI pipelines seem to be failing due to: pypa/setuptools#3102

@github-actions

This comment has been minimized.

1 similar comment
@github-actions

This comment has been minimized.

@hauntsaninja
Copy link
Collaborator

I pushed a fix for CI in #12181

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@@ -523,7 +532,7 @@ def parse_mypy_comments(
stderr = StringIO()
strict_found = False

def set_strict_flags() -> None:
def set_strict_flags(ignored: Any) -> None:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer having reasonable name/type even if ignored.

@vxgmichel
Copy link

Any update on this? The current behavior feels like a bug to me too, I'd love to see this fixed :)

This comment has been minimized.

This comment has been minimized.

Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

AutoSplit (https://github.com/Toufool/AutoSplit)
+ src/AutoSplit.py:25:1: error: Module "capture_method" does not explicitly export attribute "CaptureMethodBase"  [attr-defined]

pyjwt (https://github.com/jpadilla/pyjwt)
+ jwt/algorithms.py:190: error: Function is missing a type annotation for one or more arguments  [no-untyped-def]
+ jwt/algorithms.py:195: error: Function is missing a type annotation for one or more arguments  [no-untyped-def]
+ jwt/algorithms.py:199: error: Function is missing a type annotation for one or more arguments  [no-untyped-def]
+ jwt/api_jws.py:182: error: Function is missing a type annotation for one or more arguments  [no-untyped-def]
+ jwt/api_jws.py:228: error: Function is missing a type annotation for one or more arguments  [no-untyped-def]
+ jwt/api_jwt.py:236: error: Function is missing a type annotation for one or more arguments  [no-untyped-def]
+ jwt/api_jwt.py:287: error: Function is missing a type annotation for one or more arguments  [no-untyped-def]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants