From 42e217835ca1e2cf0cfc81ed9f367e2e19b7946a Mon Sep 17 00:00:00 2001 From: LeoLomardo Date: Tue, 4 Nov 2025 08:12:11 -0300 Subject: [PATCH 1/2] refactor --- long_functions.csv | 122 +++++++++++++++++++++++++++++++++++++++++++++ mypy/test/data.py | 108 +++++++++++++++++++++++---------------- 2 files changed, 186 insertions(+), 44 deletions(-) create mode 100644 long_functions.csv diff --git a/long_functions.csv b/long_functions.csv new file mode 100644 index 000000000000..915c608868b8 --- /dev/null +++ b/long_functions.csv @@ -0,0 +1,122 @@ +path,name,length,start,end +mypy/main.py,define_options,880,465,1344 +mypy/options.py,__init__,329,93,421 +mypy/meet.py,is_overlapping_types,322,324,645 +mypy/checker.py,check_func_def,303,1296,1598 +mypy/constraints.py,visit_instance,274,762,1035 +mypy/test/teststubtest.py,test_has_runtime_final_decorator,254,1778,2031 +mypyc/irbuild/ll_builder.py,_construct_varargs,234,723,956 +mypy/messages.py,format_type_inner,228,2555,2782 +mypy/messages.py,report_protocol_problems,228,2118,2345 +mypy/plugins/dataclasses.py,collect_attributes,228,523,750 +mypy/messages.py,incompatible_argument,224,620,843 +mypy/modulefinder.py,_find_module,220,399,618 +mypy/typeanal.py,visit_unbound_type_nonoptional,216,298,513 +mypy/main.py,process_options,212,1347,1558 +mypy/messages.py,has_no_attr,206,362,567 +mypyc/build.py,mypycify,206,481,686 +mypy/semanal.py,check_and_set_up_type_alias,203,3956,4158 +mypyc/test/test_run.py,run_case_step,202,195,396 +mypy/checkmember.py,analyze_class_attribute_access,200,1132,1331 +mypy/typeanal.py,try_analyze_special_unbound_type,200,589,788 +mypy/test/typefixture.py,__init__,200,48,247 +mypy/subtypes.py,are_parameters_compatible,194,1747,1940 +mypy/exprtotype.py,expr_to_unanalyzed_type,189,64,252 +mypy/test/teststubtest.py,test_type_alias,188,1152,1339 +mypy/test/data.py,parse_test_case,186,57,242 +mypy/checker.py,find_isinstance_check_helper,183,6286,6468 +mypy/checker.py,check_assignment,181,3225,3405 +mypy/checkexpr.py,check_callable_call,180,1652,1831 +mypy/plugins/functools.py,handle_partial_with_callee,180,151,330 +mypy/checker.py,check_method_override_for_base_with_name,178,2269,2446 +mypyc/codegen/emitclass.py,generate_class,178,224,401 +mypy/checkexpr.py,check_op_reversible,175,3954,4128 +mypy/plugins/dataclasses.py,transform,174,231,404 +mypyc/codegen/emit.py,emit_cast,168,556,723 +mypy/build.py,load_graph,167,3098,3264 +mypy/constraints.py,infer_constraints_for_callable,167,110,276 +mypy/subtypes.py,visit_instance,167,475,641 +mypy/stubdoc.py,add_token,165,188,352 +mypy/checker.py,check_override,163,2464,2626 +mypy/checkpattern.py,visit_class_pattern,163,536,698 +mypy/semanal_namedtuple.py,build_namedtuple_typeinfo,163,502,664 +mypyc/codegen/emit.py,emit_unbox,161,838,998 +mypy/constraints.py,visit_callable_type,160,1078,1237 +mypy/fastparse.py,do_func_def,160,929,1088 +mypyc/irbuild/for_helpers.py,make_for_loop_generator,157,413,569 +mypy/test/teststubgen.py,test_infer_sig_from_docstring,157,222,378 +misc/perf_compare.py,main,155,115,269 +mypy/subtypes.py,is_callable_compatible,153,1567,1719 +mypy/checkexpr.py,visit_call_expr_inner,151,507,657 +mypy/checkexpr.py,visit_comparison_expr,148,3561,3708 +mypy/fastparse.py,fix_function_overloads,147,638,784 +mypy/typeanal.py,instantiate_type_alias,145,2091,2235 +mypy/checkexpr.py,check_overload_call,142,2672,2813 +mypy/semanal.py,visit_call_expr,142,5741,5882 +mypy/test/teststubtest.py,test_enum,142,1343,1484 +mypy/build.py,validate_meta,141,1455,1595 +mypyc/codegen/emitmodule.py,generate_shared_lib_init,141,772,912 +mypy/checkexpr.py,check_argument_types,139,2486,2624 +mypy/checkexpr.py,infer_function_type_arguments,138,2057,2194 +mypy/checker.py,refine_identity_comparison_expression,137,6837,6973 +mypyc/codegen/emitmodule.py,generate_c_for_modules,137,540,676 +mypyc/ir/class_ir.py,__init__,137,88,224 +mypy/stubgen.py,parse_options,136,1898,2033 +mypy/stubtest.py,test_stubs,135,2224,2358 +mypy/checkmember.py,analyze_member_var_access,132,522,653 +mypy/test/teststubtest.py,test_overload,132,745,876 +mypy/checker.py,check_overlapping_overloads,130,874,1003 +mypy/checkexpr.py,dangerous_comparison,130,3726,3855 +mypy/build.py,__init__,129,633,761 +mypy/build.py,write_cache,128,1607,1734 +mypy/stubtest.py,get_mypy_type_of_runtime_value,127,1875,2001 +mypy/checkpattern.py,visit_sequence_pattern,125,230,354 +mypy/dmypy_server.py,fine_grained_increment_follow_imports,125,601,725 +mypyc/irbuild/statement.py,emit_yield_from_or_await,125,1101,1225 +mypy/typeanal.py,analyze_unbound_type_without_type_info,122,912,1033 +mypy/checkexpr.py,check_call,121,1530,1650 +mypy/subtypes.py,is_protocol_implementation,120,1158,1277 +mypyc/irbuild/classdef.py,transform_class_def,120,88,207 +mypyc/irbuild/function.py,gen_func_item,120,169,288 +mypy/server/update.py,update_module_isolated,120,561,680 +mypy/checker.py,refine_parent_types,119,6699,6817 +mypy/semanal_namedtuple.py,parse_namedtuple_args,119,338,456 +mypy/stubtest.py,_verify_signature,118,1055,1172 +mypy/test/meta/test_update_data.py,test_update_data,116,20,135 +mypy/semanal.py,analyze_func_def,115,934,1048 +mypy/checker.py,comparison_type_narrowing_helper,114,6470,6583 +mypy/main.py,main,114,62,175 +mypy/build.py,__init__,113,1961,2073 +mypy/checker.py,check_return_stmt,113,4895,5007 +mypyc/irbuild/ll_builder.py,binary_op,113,1393,1505 +mypy/test/test_find_sources.py,test_find_sources_exclude,113,264,376 +mypy/semanal_typeddict.py,analyze_typeddict_classdef,111,70,180 +mypy/plugins/enums.py,enum_value_callback,111,160,270 +mypy/semanal.py,visit_type_alias_stmt,110,5551,5660 +mypy/checkexpr.py,check_op,109,4130,4238 +mypyc/analysis/dataflow.py,run_analysis,109,514,622 +misc/incremental_checker.py,main,108,395,502 +mypy/checker.py,check_simple_assignment,108,4587,4694 +mypy/checkexpr.py,visit_op_expr,108,3452,3559 +mypy/semanal_namedtuple.py,check_namedtuple,108,222,329 +mypy/stubgenc.py,infer_c_method_args,108,939,1046 +mypyc/irbuild/prepare.py,prepare_class_def,108,348,455 +mypy/checkmember.py,analyze_descriptor_access,107,664,770 +mypy/config_parser.py,parse_section,107,483,589 +mypy/stubgenc.py,get_default_function_sig,107,270,376 +mypy/constraints.py,_infer_constraints,106,323,428 +mypy/join.py,join_tuples,106,455,560 +mypyc/irbuild/statement.py,transform_try_finally_stmt_async,106,758,863 +mypy/meet.py,narrow_declared_type,105,116,220 +mypy/stubgenc.py,generate_class_stub,105,804,908 +mypy/test/teststubtest.py,test_property,105,880,984 +mypy/build.py,process_stale_scc,104,3458,3561 +mypy/checkexpr.py,visit_tuple_expr,104,5147,5250 +mypy/messages.py,pretty_callable,103,2951,3053 +mypy/semanal_enum.py,parse_enum_call_args,102,157,258 +mypy/stubtest.py,verify_typeinfo,102,609,710 +mypy/checker.py,intersect_instances,101,5810,5910 +mypy/checkexpr.py,union_overload_result,101,3017,3117 +mypy/constraints.py,visit_tuple_type,101,1250,1350 +mypy/errors.py,add_error_info,101,603,703 +mypy/server/astdiff.py,snapshot_definition,101,231,331 diff --git a/mypy/test/data.py b/mypy/test/data.py index 5b0ad84c0ba7..ea41c194f34f 100644 --- a/mypy/test/data.py +++ b/mypy/test/data.py @@ -14,7 +14,7 @@ from dataclasses import dataclass from pathlib import Path from re import Pattern -from typing import Any, Final, NamedTuple, NoReturn, Union +from typing import Any, Callable, Final, NamedTuple, NoReturn, Union from typing_extensions import TypeAlias as _TypeAlias import pytest @@ -54,6 +54,66 @@ def _file_arg_to_module(filename: str) -> str: return ".".join(parts) +def _handle_out_section( + item: TestItem, + case: DataDrivenTestCase, + output: list[str], + output2: dict[int, list[str]], + out_section_missing: bool, + item_fail: Callable[[str], NoReturn], +) -> bool: + """Handle an "out" / "outN" section from a test item. + + Mutates `output` (in-place) or `output2` and returns the updated + `out_section_missing` flag. + """ + if item.arg is None: + args = [] + else: + args = item.arg.split(",") + + version_check = True + for arg in args: + if arg.startswith("version"): + compare_op = arg[7:9] + if compare_op not in {">=", "=="}: + item_fail("Only >= and == version checks are currently supported") + version_str = arg[9:] + try: + version = tuple(int(x) for x in version_str.split(".")) + except ValueError: + item_fail(f"{version_str!r} is not a valid python version") + if compare_op == ">=": + if version <= defaults.PYTHON3_VERSION: + item_fail( + f"{arg} always true since minimum runtime version is {defaults.PYTHON3_VERSION}" + ) + version_check = sys.version_info >= version + elif compare_op == "==": + if version < defaults.PYTHON3_VERSION: + item_fail( + f"{arg} always false since minimum runtime version is {defaults.PYTHON3_VERSION}" + ) + if not 1 < len(version) < 4: + item_fail( + f'Only minor or patch version checks are currently supported with "==": {version_str!r}' + ) + version_check = sys.version_info[: len(version)] == version + if version_check: + tmp_output = [expand_variables(line) for line in item.data] + if os.path.sep == "\\" and case.normalize_output: + tmp_output = [fix_win_path(line) for line in tmp_output] + if item.id == "out" or item.id == "out1": + # modify in place so caller's `output` reference is preserved + output[:] = tmp_output + else: + passnum = int(item.id[len("out") :]) + assert passnum > 1 + output2[passnum] = tmp_output + out_section_missing = False + return out_section_missing + + def parse_test_case(case: DataDrivenTestCase) -> None: """Parse and prepare a single case from suite with test case descriptions. @@ -150,49 +210,9 @@ def _item_fail(msg: str) -> NoReturn: full = join(base_path, m.group(1)) deleted_paths.setdefault(num, set()).add(full) elif re.match(r"out[0-9]*$", item.id): - if item.arg is None: - args = [] - else: - args = item.arg.split(",") - - version_check = True - for arg in args: - if arg.startswith("version"): - compare_op = arg[7:9] - if compare_op not in {">=", "=="}: - _item_fail("Only >= and == version checks are currently supported") - version_str = arg[9:] - try: - version = tuple(int(x) for x in version_str.split(".")) - except ValueError: - _item_fail(f"{version_str!r} is not a valid python version") - if compare_op == ">=": - if version <= defaults.PYTHON3_VERSION: - _item_fail( - f"{arg} always true since minimum runtime version is {defaults.PYTHON3_VERSION}" - ) - version_check = sys.version_info >= version - elif compare_op == "==": - if version < defaults.PYTHON3_VERSION: - _item_fail( - f"{arg} always false since minimum runtime version is {defaults.PYTHON3_VERSION}" - ) - if not 1 < len(version) < 4: - _item_fail( - f'Only minor or patch version checks are currently supported with "==": {version_str!r}' - ) - version_check = sys.version_info[: len(version)] == version - if version_check: - tmp_output = [expand_variables(line) for line in item.data] - if os.path.sep == "\\" and case.normalize_output: - tmp_output = [fix_win_path(line) for line in tmp_output] - if item.id == "out" or item.id == "out1": - output = tmp_output - else: - passnum = int(item.id[len("out") :]) - assert passnum > 1 - output2[passnum] = tmp_output - out_section_missing = False + out_section_missing = _handle_out_section( + item, case, output, output2, out_section_missing, _item_fail + ) elif item.id == "triggered" and item.arg is None: triggered = item.data else: From 927a4fa7504d403ada55840d4c614d6357d94707 Mon Sep 17 00:00:00 2001 From: Leo Lomardo <80079076+LeoLomardo@users.noreply.github.com> Date: Tue, 4 Nov 2025 10:11:04 -0300 Subject: [PATCH 2/2] Delete long_functions.csv --- long_functions.csv | 122 --------------------------------------------- 1 file changed, 122 deletions(-) delete mode 100644 long_functions.csv diff --git a/long_functions.csv b/long_functions.csv deleted file mode 100644 index 915c608868b8..000000000000 --- a/long_functions.csv +++ /dev/null @@ -1,122 +0,0 @@ -path,name,length,start,end -mypy/main.py,define_options,880,465,1344 -mypy/options.py,__init__,329,93,421 -mypy/meet.py,is_overlapping_types,322,324,645 -mypy/checker.py,check_func_def,303,1296,1598 -mypy/constraints.py,visit_instance,274,762,1035 -mypy/test/teststubtest.py,test_has_runtime_final_decorator,254,1778,2031 -mypyc/irbuild/ll_builder.py,_construct_varargs,234,723,956 -mypy/messages.py,format_type_inner,228,2555,2782 -mypy/messages.py,report_protocol_problems,228,2118,2345 -mypy/plugins/dataclasses.py,collect_attributes,228,523,750 -mypy/messages.py,incompatible_argument,224,620,843 -mypy/modulefinder.py,_find_module,220,399,618 -mypy/typeanal.py,visit_unbound_type_nonoptional,216,298,513 -mypy/main.py,process_options,212,1347,1558 -mypy/messages.py,has_no_attr,206,362,567 -mypyc/build.py,mypycify,206,481,686 -mypy/semanal.py,check_and_set_up_type_alias,203,3956,4158 -mypyc/test/test_run.py,run_case_step,202,195,396 -mypy/checkmember.py,analyze_class_attribute_access,200,1132,1331 -mypy/typeanal.py,try_analyze_special_unbound_type,200,589,788 -mypy/test/typefixture.py,__init__,200,48,247 -mypy/subtypes.py,are_parameters_compatible,194,1747,1940 -mypy/exprtotype.py,expr_to_unanalyzed_type,189,64,252 -mypy/test/teststubtest.py,test_type_alias,188,1152,1339 -mypy/test/data.py,parse_test_case,186,57,242 -mypy/checker.py,find_isinstance_check_helper,183,6286,6468 -mypy/checker.py,check_assignment,181,3225,3405 -mypy/checkexpr.py,check_callable_call,180,1652,1831 -mypy/plugins/functools.py,handle_partial_with_callee,180,151,330 -mypy/checker.py,check_method_override_for_base_with_name,178,2269,2446 -mypyc/codegen/emitclass.py,generate_class,178,224,401 -mypy/checkexpr.py,check_op_reversible,175,3954,4128 -mypy/plugins/dataclasses.py,transform,174,231,404 -mypyc/codegen/emit.py,emit_cast,168,556,723 -mypy/build.py,load_graph,167,3098,3264 -mypy/constraints.py,infer_constraints_for_callable,167,110,276 -mypy/subtypes.py,visit_instance,167,475,641 -mypy/stubdoc.py,add_token,165,188,352 -mypy/checker.py,check_override,163,2464,2626 -mypy/checkpattern.py,visit_class_pattern,163,536,698 -mypy/semanal_namedtuple.py,build_namedtuple_typeinfo,163,502,664 -mypyc/codegen/emit.py,emit_unbox,161,838,998 -mypy/constraints.py,visit_callable_type,160,1078,1237 -mypy/fastparse.py,do_func_def,160,929,1088 -mypyc/irbuild/for_helpers.py,make_for_loop_generator,157,413,569 -mypy/test/teststubgen.py,test_infer_sig_from_docstring,157,222,378 -misc/perf_compare.py,main,155,115,269 -mypy/subtypes.py,is_callable_compatible,153,1567,1719 -mypy/checkexpr.py,visit_call_expr_inner,151,507,657 -mypy/checkexpr.py,visit_comparison_expr,148,3561,3708 -mypy/fastparse.py,fix_function_overloads,147,638,784 -mypy/typeanal.py,instantiate_type_alias,145,2091,2235 -mypy/checkexpr.py,check_overload_call,142,2672,2813 -mypy/semanal.py,visit_call_expr,142,5741,5882 -mypy/test/teststubtest.py,test_enum,142,1343,1484 -mypy/build.py,validate_meta,141,1455,1595 -mypyc/codegen/emitmodule.py,generate_shared_lib_init,141,772,912 -mypy/checkexpr.py,check_argument_types,139,2486,2624 -mypy/checkexpr.py,infer_function_type_arguments,138,2057,2194 -mypy/checker.py,refine_identity_comparison_expression,137,6837,6973 -mypyc/codegen/emitmodule.py,generate_c_for_modules,137,540,676 -mypyc/ir/class_ir.py,__init__,137,88,224 -mypy/stubgen.py,parse_options,136,1898,2033 -mypy/stubtest.py,test_stubs,135,2224,2358 -mypy/checkmember.py,analyze_member_var_access,132,522,653 -mypy/test/teststubtest.py,test_overload,132,745,876 -mypy/checker.py,check_overlapping_overloads,130,874,1003 -mypy/checkexpr.py,dangerous_comparison,130,3726,3855 -mypy/build.py,__init__,129,633,761 -mypy/build.py,write_cache,128,1607,1734 -mypy/stubtest.py,get_mypy_type_of_runtime_value,127,1875,2001 -mypy/checkpattern.py,visit_sequence_pattern,125,230,354 -mypy/dmypy_server.py,fine_grained_increment_follow_imports,125,601,725 -mypyc/irbuild/statement.py,emit_yield_from_or_await,125,1101,1225 -mypy/typeanal.py,analyze_unbound_type_without_type_info,122,912,1033 -mypy/checkexpr.py,check_call,121,1530,1650 -mypy/subtypes.py,is_protocol_implementation,120,1158,1277 -mypyc/irbuild/classdef.py,transform_class_def,120,88,207 -mypyc/irbuild/function.py,gen_func_item,120,169,288 -mypy/server/update.py,update_module_isolated,120,561,680 -mypy/checker.py,refine_parent_types,119,6699,6817 -mypy/semanal_namedtuple.py,parse_namedtuple_args,119,338,456 -mypy/stubtest.py,_verify_signature,118,1055,1172 -mypy/test/meta/test_update_data.py,test_update_data,116,20,135 -mypy/semanal.py,analyze_func_def,115,934,1048 -mypy/checker.py,comparison_type_narrowing_helper,114,6470,6583 -mypy/main.py,main,114,62,175 -mypy/build.py,__init__,113,1961,2073 -mypy/checker.py,check_return_stmt,113,4895,5007 -mypyc/irbuild/ll_builder.py,binary_op,113,1393,1505 -mypy/test/test_find_sources.py,test_find_sources_exclude,113,264,376 -mypy/semanal_typeddict.py,analyze_typeddict_classdef,111,70,180 -mypy/plugins/enums.py,enum_value_callback,111,160,270 -mypy/semanal.py,visit_type_alias_stmt,110,5551,5660 -mypy/checkexpr.py,check_op,109,4130,4238 -mypyc/analysis/dataflow.py,run_analysis,109,514,622 -misc/incremental_checker.py,main,108,395,502 -mypy/checker.py,check_simple_assignment,108,4587,4694 -mypy/checkexpr.py,visit_op_expr,108,3452,3559 -mypy/semanal_namedtuple.py,check_namedtuple,108,222,329 -mypy/stubgenc.py,infer_c_method_args,108,939,1046 -mypyc/irbuild/prepare.py,prepare_class_def,108,348,455 -mypy/checkmember.py,analyze_descriptor_access,107,664,770 -mypy/config_parser.py,parse_section,107,483,589 -mypy/stubgenc.py,get_default_function_sig,107,270,376 -mypy/constraints.py,_infer_constraints,106,323,428 -mypy/join.py,join_tuples,106,455,560 -mypyc/irbuild/statement.py,transform_try_finally_stmt_async,106,758,863 -mypy/meet.py,narrow_declared_type,105,116,220 -mypy/stubgenc.py,generate_class_stub,105,804,908 -mypy/test/teststubtest.py,test_property,105,880,984 -mypy/build.py,process_stale_scc,104,3458,3561 -mypy/checkexpr.py,visit_tuple_expr,104,5147,5250 -mypy/messages.py,pretty_callable,103,2951,3053 -mypy/semanal_enum.py,parse_enum_call_args,102,157,258 -mypy/stubtest.py,verify_typeinfo,102,609,710 -mypy/checker.py,intersect_instances,101,5810,5910 -mypy/checkexpr.py,union_overload_result,101,3017,3117 -mypy/constraints.py,visit_tuple_type,101,1250,1350 -mypy/errors.py,add_error_info,101,603,703 -mypy/server/astdiff.py,snapshot_definition,101,231,331