From 2295aff823db2cb7ac256ff2c026ea2d00a82cf0 Mon Sep 17 00:00:00 2001 From: Pranav Rajpal <78008260+pranavrajpal@users.noreply.github.com> Date: Sat, 28 May 2022 19:57:18 -0700 Subject: [PATCH 1/4] Set check-untyped-defs to be on by default --- mypy/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mypy/main.py b/mypy/main.py index 57727821274e..76e9cdebda7d 100644 --- a/mypy/main.py +++ b/mypy/main.py @@ -605,7 +605,7 @@ def add_invertible_flag(flag: str, add_invertible_flag('--disallow-incomplete-defs', default=False, strict_flag=True, help="Disallow defining functions with incomplete type annotations", group=untyped_group) - add_invertible_flag('--check-untyped-defs', default=False, strict_flag=True, + add_invertible_flag('--check-untyped-defs', default=True, strict_flag=True, help="Type check the interior of functions without type annotations", group=untyped_group) add_invertible_flag('--disallow-untyped-decorators', default=False, strict_flag=True, From 5cc36c5b9adbcb351a9f48905ae42f41f470b426 Mon Sep 17 00:00:00 2001 From: Pranav Rajpal <78008260+pranavrajpal@users.noreply.github.com> Date: Sat, 28 May 2022 23:34:05 -0700 Subject: [PATCH 2/4] Actually make check_untyped_defs the default Changing the default of an option apparently isn't as straightforward as just changing the default argument to add_invertible_flag. We need to also specify dest, change the name of the flag, and change the default in options.py. --- mypy/main.py | 5 +++-- mypy/options.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/mypy/main.py b/mypy/main.py index 76e9cdebda7d..33752aade2b0 100644 --- a/mypy/main.py +++ b/mypy/main.py @@ -605,8 +605,9 @@ def add_invertible_flag(flag: str, add_invertible_flag('--disallow-incomplete-defs', default=False, strict_flag=True, help="Disallow defining functions with incomplete type annotations", group=untyped_group) - add_invertible_flag('--check-untyped-defs', default=True, strict_flag=True, - help="Type check the interior of functions without type annotations", + add_invertible_flag('--no-check-untyped-defs', default=True, strict_flag=True, + dest='check_untyped_defs', + help="Don't type check the interior of functions without type annotations", group=untyped_group) add_invertible_flag('--disallow-untyped-decorators', default=False, strict_flag=True, help="Disallow decorating typed functions with untyped decorators", diff --git a/mypy/options.py b/mypy/options.py index 254af61a0645..e2ad4bba1387 100644 --- a/mypy/options.py +++ b/mypy/options.py @@ -120,7 +120,7 @@ def __init__(self) -> None: self.disallow_incomplete_defs = False # Type check unannotated functions - self.check_untyped_defs = False + self.check_untyped_defs = True # Disallow decorating typed functions with untyped decorators self.disallow_untyped_decorators = False From 10b9d364acc041949c0e8235b58a8369b5f23d25 Mon Sep 17 00:00:00 2001 From: Pranav Rajpal <78008260+pranavrajpal@users.noreply.github.com> Date: Sat, 28 May 2022 23:48:13 -0700 Subject: [PATCH 3/4] Update help text and strict settings Remove strict_flag=True to prevent check-untyped-defs from being disabled when --strict is passed. Also update the help text for the untyped group to remove the statement referring to --check-untyped-defs being disabled by default. --- mypy/main.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mypy/main.py b/mypy/main.py index 33752aade2b0..a242e766067a 100644 --- a/mypy/main.py +++ b/mypy/main.py @@ -588,12 +588,13 @@ def add_invertible_flag(flag: str, help="Disallow subclassing values of type 'Any' when defining classes", group=disallow_any_group) + # TODO: is the Note really helpful if --check-untyped-defs is enabled by default? (Maybe + # reword it to emphasize that mypy doesn't infer return types?) untyped_group = parser.add_argument_group( title='Untyped definitions and calls', description="Configure how untyped definitions and calls are handled. " - "Note: by default, mypy ignores any untyped function definitions " - "and assumes any calls to such functions have a return " - "type of 'Any'.") + "Note: by default, mypy assumes any calls to untyped " + "functions have a return type of 'Any'.") add_invertible_flag('--disallow-untyped-calls', default=False, strict_flag=True, help="Disallow calling functions without type annotations" " from functions with type annotations", @@ -605,7 +606,7 @@ def add_invertible_flag(flag: str, add_invertible_flag('--disallow-incomplete-defs', default=False, strict_flag=True, help="Disallow defining functions with incomplete type annotations", group=untyped_group) - add_invertible_flag('--no-check-untyped-defs', default=True, strict_flag=True, + add_invertible_flag('--no-check-untyped-defs', default=True, dest='check_untyped_defs', help="Don't type check the interior of functions without type annotations", group=untyped_group) From dcc882898d2c511483aeb3134855e37bfb3e8f8f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 2 Jan 2026 23:10:52 +0000 Subject: [PATCH 4/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mypy/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mypy/main.py b/mypy/main.py index f52bde46d2af..458e1740cd1e 100644 --- a/mypy/main.py +++ b/mypy/main.py @@ -747,7 +747,7 @@ def add_invertible_flag( title="Untyped definitions and calls", description="Configure how untyped definitions and calls are handled. " "Note: by default, mypy assumes any calls to untyped " - "functions have a return type of 'Any'." + "functions have a return type of 'Any'.", ) add_invertible_flag( "--disallow-untyped-calls", @@ -784,7 +784,7 @@ def add_invertible_flag( add_invertible_flag( "--no-check-untyped-defs", default=True, - dest='check_untyped_defs', + dest="check_untyped_defs", help="Don't type check the interior of functions without type annotations", group=untyped_group, )