8000 Add option to selectively disable --disallow-untyped-calls by ilevkivskyi · Pull Request #15845 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Add option to selectively disable --disallow-untyped-calls #15845

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

Merged
merged 4 commits into from
Aug 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Try different name for the flag
  • Loading branch information
Ivan Levkivskyi committed Aug 13, 2023
commit 83df5ddfa33d72074788e3181eaa85a43a4e0712
8 changes: 4 additions & 4 deletions docs/source/command_line.rst
Original file line number Diff line number Diff line change
Expand Up @@ -350,18 +350,18 @@ definitions or calls.
This flag reports an error whenever a function with type annotations
calls a function defined without annotations.

.. option:: --untyped-call-exception
.. option:: --untyped-calls-exclude

This flag allows to selectively disable :option:`--disallow-untyped-calls`
for functions and methods defined in specific packages, modules, or classes.
Note that each exception entry acts as a prefix. For example (assuming there
Note that each exclude entry acts as a prefix. For example (assuming there
are no type annotations for ``third_party_lib`` available):

.. code-block:: python

# mypy --disallow-untyped-calls
# --untyped-call-exception=third_party_lib.module_a
# --untyped-call-exception=foo.A
# --untyped-calls-exclude=third_party_lib.module_a
# --untyped-calls-exclude=foo.A
from third_party_lib.module_a import some_func
from third_party_lib.module_b import other_func
import foo
Expand Down
8 changes: 4 additions & 4 deletions docs/source/config_file.rst
Original file line number Diff line number Diff line change
Expand Up @@ -505,23 +505,23 @@ section of the command line docs.
will disable this check inside ``some.library``, not for your code that
imports ``some.library``. If you want to selectively disable this check for
all your code that imports ``some.library`` you should instead use
:confval:`untyped_call_exception`, for example:
:confval:`untyped_calls_exclude`, for example:

.. code-block:: ini

[mypy]
disallow_untyped_calls = True
untyped_call_exception = some.library
untyped_calls_exclude = some.library

.. confval:: untyped_call_exception
.. confval:: untyped_calls_exclude

:type: comma-separated list of strings

Selectively excludes functions and methods defined in specific packages,
modules, and classes from action of :confval:`disallow_untyped_calls`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Mention that this also applies to submodules of packages (i.e. everything inside that prefix).

This also applies to all submodules of packages (i.e. everything inside
a given prefix). Note, this option does not support per-file configuration,
the exception list is defined globally for all your code.
the exclusions list is defined globally for all your code.

.. confval:: disallow_untyped_defs

Expand Down
2 changes: 1 addition & 1 deletion mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ def visit_call_expr_inner(self, e: CallExpr, allow_none_return: bool = False) ->
fullname = self.method_fullname(object_type, member)
if not fullname or not any(
fullname == p or fullname.startswith(f"{p}.")
for p in self.chk.options.untyped_call_exception
for p in self.chk.options.untyped_calls_exclude
):
self.msg.untyped_function_call(callee_type, e)

Expand Down
4 changes: 2 additions & 2 deletions mypy/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def split_commas(value: str) -> list[str]:
"plugins": lambda s: [p.strip() for p in split_commas(s)],
"always_true": lambda s: [p.strip() for p in split_commas(s)],
"always_false": lambda s: [p.strip() for p in split_commas(s)],
"untyped_call_exception": lambda s: validate_package_allow_list(
"untyped_calls_exclude": lambda s: validate_package_allow_list(
[p.strip() for p in split_commas(s)]
),
"enable_incomplete_feature": lambda s: [p.strip() for p in split_commas(s)],
Expand All @@ -204,7 +204,7 @@ def split_commas(value: str) -> list[str]:
"plugins": try_split,
"always_true": try_split,
"always_false": try_split,
"untyped_call_exception": lambda s: validate_package_allow_list(try_split(s)),
"untyped_calls_exclude": lambda s: validate_package_allow_list(try_split(s)),
"enable_incomplete_feature": try_split,
"disable_error_code": lambda s: validate_codes(try_split(s)),
"enable_error_code": lambda s: validate_codes(try_split(s)),
Expand Down
4 changes: 2 additions & 2 deletions mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ def add_invertible_flag(
group=untyped_group,
)
untyped_group.add_argument(
"--untyped-call-exception",
"--untyped-calls-exclude",
metavar="MODULE",
action="append",
default=[],
Expand Down Expand Up @@ -1320,7 +1320,7 @@ def set_strict_flags() -> None:
% ", ".join(sorted(overlap))
)

validate_package_allow_list(options.untyped_call_exception)
validate_package_allow_list(options.untyped_calls_exclude)

# Process `--enable-error-code` and `--disable-error-code` flags
disabled_codes = set(options.disable_error_code)
Expand Down
2 changes: 1 addition & 1 deletion mypy/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def __init__(self) -> None:

# Always allow untyped calls for function coming from modules/packages
# in this list (each item effectively acts as a prefix match)
self.untyped_call_exception: list[str] = []
self.untyped_calls_exclude: list[str] = []

# Disallow defining untyped (or incompletely typed) functions
self.disallow_untyped_defs = False
Expand Down
4 changes: 2 additions & 2 deletions test-data/unit/check-flags.test
Original file line number Diff line number Diff line change
Expand Up @@ -2078,7 +2078,7 @@ f(reveal_type(y)) # E: Call to untyped function "f" in typed context \
# N: Revealed type is "builtins.int"

[case testDisallowUntypedCallsAllowListFlags]
# flags: --disallow-untyped-calls --untyped-call-exception=foo --untyped-call-exception=bar.A
# flags: --disallow-untyped-calls --untyped-calls-exclude=foo --untyped-calls-exclude=bar.A
from foo import test_foo
from bar import A, B
from baz import test_baz
Expand Down Expand Up @@ -2130,7 +2130,7 @@ def test_baz(x): pass
[file mypy.ini]
\[mypy]
disallow_untyped_calls = True
untyped_call_exception = foo, bar.A
untyped_calls_exclude = foo, bar.A

[case testPerModuleErrorCodes]
# flags: --config-file tmp/mypy.ini
Expand Down
0