From bdd377c2643a26861370d3219d52349bbe63d23f Mon Sep 17 00:00:00 2001 From: AlexWaygood Date: Fri, 28 Jul 2023 21:33:03 +0100 Subject: [PATCH 1/4] Argument clinic: enable mypy's `--warn-return-any` setting --- Tools/clinic/clinic.py | 2 +- Tools/clinic/mypy.ini | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index 6bfa6d0d568146..123c117377a3a7 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -4288,7 +4288,7 @@ def eval_ast_expr( globals: dict[str, Any], *, filename: str = '-' -) -> FunctionType: +) -> Any: """ Takes an ast.Expr node. Compiles and evaluates it. Returns the result of the expression. diff --git a/Tools/clinic/mypy.ini b/Tools/clinic/mypy.ini index 4aa65a5c14489f..4cfc05bec01608 100644 --- a/Tools/clinic/mypy.ini +++ b/Tools/clinic/mypy.ini @@ -5,11 +5,8 @@ pretty = True # make sure clinic can still be run on Python 3.10 python_version = 3.10 -# be strict... +# and be strict! strict = True strict_concatenate = True enable_error_code = ignore-without-code,redundant-expr warn_unreachable = True - -# ...except for one extra rule we can't enable just yet -warn_return_any = False From a5103bef7682f04062c393fae08584f3905f8ed3 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Fri, 28 Jul 2023 22:11:12 +0100 Subject: [PATCH 2/4] add an essay explaining the return annotation --- Tools/clinic/clinic.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index 123c117377a3a7..4f606a5baaa2aa 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -4283,6 +4283,11 @@ class float_return_converter(double_return_converter): cast = '(double)' +# What do we do in this function? +# We take an arbitrary AST node, compile the node into a function object, +# call that function with 0 arguments, and return whatever the call returns. +# The only possible return annotations here would be `object` or `Any`, +# and `object` would be too annoying. Return `Any`! def eval_ast_expr( node: ast.expr, globals: dict[str, Any], From 8aed224000a03424cab7a19e44a009aa3a8287af Mon Sep 17 00:00:00 2001 From: AlexWaygood Date: Sat, 29 Jul 2023 12:20:37 +0100 Subject: [PATCH 3/4] Revert "add an essay explaining the return annotation" This reverts commit a5103bef7682f04062c393fae08584f3905f8ed3. --- Tools/clinic/clinic.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index 4f606a5baaa2aa..123c117377a3a7 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -4283,11 +4283,6 @@ class float_return_converter(double_return_converter): cast = '(double)' -# What do we do in this function? -# We take an arbitrary AST node, compile the node into a function object, -# call that function with 0 arguments, and return whatever the call returns. -# The only possible return annotations here would be `object` or `Any`, -# and `object` would be too annoying. Return `Any`! def eval_ast_expr( node: ast.expr, globals: dict[str, Any], From 6df4ba30b9f10dbc026691edb2f121497953c763 Mon Sep 17 00:00:00 2001 From: AlexWaygood Date: Sat, 29 Jul 2023 12:22:52 +0100 Subject: [PATCH 4/4] Improve docstring slightly --- Tools/clinic/clinic.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index 123c117377a3a7..cb999c156ee28b 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -4290,8 +4290,9 @@ def eval_ast_expr( filename: str = '-' ) -> Any: """ - Takes an ast.Expr node. Compiles and evaluates it. - Returns the result of the expression. + Takes an ast.Expr node. Compiles it into a function object, + then calls the function object with 0 arguments. + Returns the result of that function call. globals represents the globals dict the expression should see. (There's no equivalent for "locals" here.)