ruff/crates/ty_python_semantic/resources/mdtest/snapshots
Alex Waygood ce8b744f17
[ty] Only calculate information for unresolved-reference subdiagnostic if we know we'll emit the diagnostic (#18465)
## Summary

This optimizes some of the logic added in
https://github.com/astral-sh/ruff/pull/18444. In general, we only
calculate information for subdiagnostics if we know we'll actually emit
the diagnostic. The check to see whether we'll emit the diagnostic is
work we'll definitely have to do whereas the the work to gather
information for a subdiagnostic isn't work we necessarily have to do if
the diagnostic isn't going to be emitted at all.

This PR makes us lazier about gathering the information we need for the
subdiagnostic, and moves all the subdiagnostic logic into one function
rather than having some `unresolved-reference` subdiagnostic logic in
`infer.rs` and some in `diagnostic.rs`.

## Test Plan

`cargo test -p ty_python_semantic`
2025-06-04 20:41:00 +01:00
..
all_members.md_-_List_all_members_-_Basic_functionality_(6b9531a70334bfad).snap [ty] List available members for a given type (#18251) 2025-05-30 11:24:20 -04:00
annotations.md_-_Assignment_with_anno…_-_PEP-604_in_non-type-…_-_Earlier_versions_(f2859c9800f37c7).snap [ty] Tell the user why we inferred the Python version we inferred (#18082) 2025-05-21 11:06:27 -04:00
assert_never.md_-_`assert_never`_-_Basic_functionality_(78e7b52096b8d36c).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
assert_type.md_-_`assert_type`_-_Basic_(c507788da2659ec9).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
attribute_assignment…_-_Attribute_assignment_-_Data_descriptors_-_Invalid_`__set__`_me…_(116c27bd98838df7).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
attribute_assignment…_-_Attribute_assignment_-_Data_descriptors_-_Invalid_argument_typ…_(a903c11fedbc5020).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
attribute_assignment…_-_Attribute_assignment_-_Instance_attributes_…_(ebfb3de6d1b96b23).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
attribute_assignment…_-_Attribute_assignment_-_Possibly-unbound_att…_(e5bdf78c427cb7fc).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
attribute_assignment…_-_Attribute_assignment_-_Pure_instance_attrib…_(d13d57d3cc36face).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
attribute_assignment…_-_Attribute_assignment_-_Setting_attributes_o…_(467e26496f4c0c13).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
attribute_assignment…_-_Attribute_assignment_-_Unknown_attributes_(368ba83a71ef2120).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
attribute_assignment…_-_Attribute_assignment_-_`ClassVar`s_(8d7cca27987b099d).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
attributes.md_-_Attributes_-_Invalid_access_to_at…_(5457445ffed43a87).snap [ty] Only calculate information for unresolved-reference subdiagnostic if we know we'll emit the diagnostic (#18465) 2025-06-04 20:41:00 +01:00
basic.md_-_Structures_-_Attempting_to_import…_(2fcfcf567587a056).snap [ty] Improve diagnostics if the user attempts to import a stdlib module that does not exist on their configured Python version (#18403) 2025-06-02 10:52:26 +00:00
basic.md_-_Structures_-_Attempting_to_import…_(c14954eefd15211f).snap [ty] Improve diagnostics if the user attempts to import a stdlib module that does not exist on their configured Python version (#18403) 2025-06-02 10:52:26 +00:00
basic.md_-_Structures_-_Multiple_objects_imp…_(cbfbf5ff94e6e104).snap [ty] Add note to `unresolved-import` hinting to users to configure their Python environment (#18207) 2025-05-19 17:24:25 -04:00
basic.md_-_Structures_-_Unresolvable_module_…_(846453deaca1071c).snap [ty] Add note to `unresolved-import` hinting to users to configure their Python environment (#18207) 2025-05-19 17:24:25 -04:00
basic.md_-_Structures_-_Unresolvable_submodu…_(4fad4be9778578b7).snap [ty] Add note to `unresolved-import` hinting to users to configure their Python environment (#18207) 2025-05-19 17:24:25 -04:00
for.md_-_For_loops_-_Bad_`__getitem__`_me…_(3ffe352bb3a76715).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
for.md_-_For_loops_-_Invalid_iterable_(3153247bb9a9b72a).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
for.md_-_For_loops_-_New_over_old_style_i…_(a90ba167a7c191eb).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
for.md_-_For_loops_-_No_`__iter__`_method…_(36425dbcbd793d2b).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
for.md_-_For_loops_-_Possibly-not-callabl…_(49a21e4b7fe6e97b).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
for.md_-_For_loops_-_Possibly_invalid_`__…_(6805a6032e504b63).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
for.md_-_For_loops_-_Possibly_invalid_`__…_(6388761c90a0555c).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
for.md_-_For_loops_-_Possibly_invalid_`__…_(c626bde8651b643a).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
for.md_-_For_loops_-_Possibly_unbound_`__…_(3b75cc467e6e012).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
for.md_-_For_loops_-_Possibly_unbound_`__…_(8745233539d31200).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
for.md_-_For_loops_-_Possibly_unbound_`__…_(b1ce0da35c06026).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
for.md_-_For_loops_-_Union_type_as_iterab…_(6177bb6d13a22241).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
for.md_-_For_loops_-_Union_type_as_iterab…_(ba36fbef63a14969).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
for.md_-_For_loops_-_With_non-callable_it…_(a1cdf01ad69ac37c).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
for.md_-_For_loops_-_`__iter__`_does_not_…_(92e3fdd69edad63d).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
for.md_-_For_loops_-_`__iter__`_method_wi…_(1136c0e783d61ba4).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
for.md_-_For_loops_-_`__iter__`_returns_a…_(707bd02a22c4acc8).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
functions.md_-_Generic_functions___L…_-_Inferring_a_bound_ty…_(d50204b9d91b7bd1).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
functions.md_-_Generic_functions___L…_-_Inferring_a_constrai…_(48ab83f977c109b4).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
functions.md_-_Generic_functions___P…_-_Inferring_a_bound_ty…_(5935d14c26afe407).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
functions.md_-_Generic_functions___P…_-_Inferring_a_constrai…_(d2c475fccc70a8e2).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
instances.md_-_Binary_operations_on…_-_Operations_involving…_(492b1163b8163c05).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
invalid.md_-_Tests_for_invalid_ty…_-_Diagnostics_for_comm…_-_Module-literal_used_…_(652fec4fd4a6c63a).snap [ty] Improve `invalid-type-form` diagnostic where a module-literal type is used in a type expression and the module has a member which would be valid in a type expression (#18244) 2025-05-21 15:38:56 -04:00
invalid_argument_typ…_-_Invalid_argument_typ…_-_Basic_(16be9d90a741761).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
invalid_argument_typ…_-_Invalid_argument_typ…_-_Calls_to_methods_(4b3b8695d519a02).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
invalid_argument_typ…_-_Invalid_argument_typ…_-_Different_files_(d02c38e2dd054b4c).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
invalid_argument_typ…_-_Invalid_argument_typ…_-_Different_source_ord…_(9b0bf549733d3f0a).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
invalid_argument_typ…_-_Invalid_argument_typ…_-_Many_parameters_(ee38fd34ceba3293).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
invalid_argument_typ…_-_Invalid_argument_typ…_-_Many_parameters_acro…_(1d5d112808c49e9d).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
invalid_argument_typ…_-_Invalid_argument_typ…_-_Many_parameters_with…_(4bc5c16cd568b8ec).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
invalid_argument_typ…_-_Invalid_argument_typ…_-_Test_calling_a_funct…_(3b18271a821a59b).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
invalid_argument_typ…_-_Invalid_argument_typ…_-_Tests_for_a_variety_…_-_Keyword_only_argumen…_(8d9f18c78137411).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
invalid_argument_typ…_-_Invalid_argument_typ…_-_Tests_for_a_variety_…_-_Mix_of_arguments_(cfc64b1136058112).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
invalid_argument_typ…_-_Invalid_argument_typ…_-_Tests_for_a_variety_…_-_One_keyword_argument_(cc34b2f7d19d427e).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
invalid_argument_typ…_-_Invalid_argument_typ…_-_Tests_for_a_variety_…_-_Only_positional_(3dc93b1709eb3be9).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
invalid_argument_typ…_-_Invalid_argument_typ…_-_Tests_for_a_variety_…_-_Synthetic_arguments_(4c09844bbbf47741).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
invalid_argument_typ…_-_Invalid_argument_typ…_-_Tests_for_a_variety_…_-_Variadic_arguments_(e26a3e7b2773a63b).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
invalid_argument_typ…_-_Invalid_argument_typ…_-_Tests_for_a_variety_…_-_Variadic_keyword_arg…_(4c855e39ea6baeaf).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
membership_test.md_-_Comparison___Membersh…_-_Return_type_that_doe…_(feccf6b9da1e7cd3).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
mro.md_-_Method_Resolution_Or…_-_Unresolvable_MROs_in…_(e2b355c09a967862).snap [ty] Do not carry the generic context of `Protocol` or `Generic` in the `ClassBase` enum (#17989) 2025-05-22 21:37:03 -04:00
mro.md_-_Method_Resolution_Or…_-_`__bases__`_includes…_(d2532518c44112c8).snap [ty] Split `invalid-base` error code into two error codes (#18245) 2025-05-21 18:02:39 -04:00
mro.md_-_Method_Resolution_Or…_-_`__bases__`_lists_th…_(6f8d0bf648c4b305).snap [ty] Split `invalid-base` error code into two error codes (#18245) 2025-05-21 18:02:39 -04:00
mro.md_-_Method_Resolution_Or…_-_`__bases__`_lists_wi…_(ea7ebc83ec359b54).snap [ty] Allow unions including `Any`/`Unknown` as bases (#18094) 2025-05-16 06:57:26 +02:00
no_matching_overload…_-_No_matching_overload…_-_A_class_constructor_…_(dd9f8a8f736a329).snap [ty] Improve invalid method calls for unmatched overloads (#18122) 2025-05-15 11:39:14 -04:00
no_matching_overload…_-_No_matching_overload…_-_A_method_call_with_u…_(31cb5f881221158e).snap [ty] Improve invalid method calls for unmatched overloads (#18122) 2025-05-15 11:39:14 -04:00
no_matching_overload…_-_No_matching_overload…_-_Call_to_function_wit…_(dd80c593d9136f35).snap ty_python_semantic: improve failed overloaded function call 2025-05-14 11:13:41 -04:00
no_matching_overload…_-_No_matching_overload…_-_Call_to_function_wit…_(f66e3a8a3977c472).snap ty_python_semantic: improve failed overloaded function call 2025-05-14 11:13:41 -04:00
no_matching_overload…_-_No_matching_overload…_-_Calls_to_overloaded_…_(3553d085684e16a0).snap ty_python_semantic: improve failed overloaded function call 2025-05-14 11:13:41 -04:00
no_matching_overload…_-_No_matching_overload…_-_Calls_to_overloaded_…_(36814b28492c01d2).snap ty_python_semantic: improve failed overloaded function call 2025-05-14 11:13:41 -04:00
not.md_-_Unary_not_-_Object_that_implemen…_(ab3f546bf004e24d).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
overloads.md_-_Overloads_-_Invalid_-_At_least_two_overloa…_(84dadf8abd8f2f2).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
overloads.md_-_Overloads_-_Invalid_-_Inconsistent_decorat…_-_`@classmethod`_(aaa04d4cfa3adaba).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
overloads.md_-_Overloads_-_Invalid_-_Inconsistent_decorat…_-_`@final`_(f8e529ec23a61665).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
overloads.md_-_Overloads_-_Invalid_-_Inconsistent_decorat…_-_`@override`_(2df210735ca532f9).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
overloads.md_-_Overloads_-_Invalid_-_Overload_without_an_…_-_Regular_modules_(5c8e81664d1c7470).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
protocols.md_-_Protocols_-_Calls_to_protocol_cl…_(288988036f34ddcf).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
protocols.md_-_Protocols_-_Invalid_calls_to_`ge…_(3d0c4ee818c4d8d5).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
protocols.md_-_Protocols_-_Narrowing_of_protoco…_(98257e7c2300373).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
return_type.md_-_Function_return_type_-_Diagnostics_for_`inv…_(35563a74094b14d5).snap [ty] Add diagnosis for function with no return statement but with return type annotation (#18359) 2025-05-29 23:17:18 +00:00
return_type.md_-_Function_return_type_-_Generator_functions_(d9ed06b61b14fd4c).snap [ty] Fix Inconsistent casing in diagnostic (#18084) 2025-05-14 08:26:48 +02:00
return_type.md_-_Function_return_type_-_Invalid_conditional_…_(94c036c5d3803ab2).snap [ty] Fix Inconsistent casing in diagnostic (#18084) 2025-05-14 08:26:48 +02:00
return_type.md_-_Function_return_type_-_Invalid_implicit_ret…_(3d2d19aa49b28f1c).snap [ty] Add diagnosis for function with no return statement but with return type annotation (#18359) 2025-05-29 23:17:18 +00:00
return_type.md_-_Function_return_type_-_Invalid_implicit_ret…_(393cb38bf7119649).snap [ty] Add diagnosis for function with no return statement but with return type annotation (#18359) 2025-05-29 23:17:18 +00:00
return_type.md_-_Function_return_type_-_Invalid_return_type_(a91e0c67519cd77f).snap [ty] Add diagnosis for function with no return statement but with return type annotation (#18359) 2025-05-29 23:17:18 +00:00
return_type.md_-_Function_return_type_-_Invalid_return_type_…_(c3a523878447af6b).snap [ty] Add diagnosis for function with no return statement but with return type annotation (#18359) 2025-05-29 23:17:18 +00:00
rich_comparison.md_-_Comparison___Rich_Com…_-_Chained_comparisons_…_(c391c13e2abc18a0).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
semantic_syntax_erro…_-_Semantic_syntax_erro…_-_`async`_comprehensio…_-_Python_3.10_(96aa8ec77d46553d).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
shadowing.md_-_Shadowing_-_Implicit_class_shado…_(c8ff9e3a079e8bd5).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
shadowing.md_-_Shadowing_-_Implicit_function_sh…_(a1515328b775ebc1).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
sync.md_-_With_statements_-_Accidental_use_of_no…_(b07503f9b773ea61).snap [ty] Add hint if async context manager is used in non-async with statement (#18299) 2025-05-26 21:34:47 +02:00
tuples.md_-_Comparison___Tuples_-_Chained_comparisons_…_(f45f1da2f8ca693d).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
tuples.md_-_Comparison___Tuples_-_Equality_with_elemen…_(39b614d4707c0661).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
union_call.md_-_Calling_a_union_of_f…_-_A_smaller_scale_exam…_(c24ecd8582e5eb2f).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
union_call.md_-_Calling_a_union_of_f…_-_Multiple_variants_bu…_(d840ac443ca8ec7f).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
union_call.md_-_Calling_a_union_of_f…_-_Try_to_cover_all_pos…_-_Cover_keyword_argume…_(ad1d489710ee2a34).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
union_call.md_-_Calling_a_union_of_f…_-_Try_to_cover_all_pos…_-_Cover_non-keyword_re…_(707b284610419a54).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
unpacking.md_-_Unpacking_-_Exactly_too_few_valu…_(f920ea85eefe9cfe).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
unpacking.md_-_Unpacking_-_Exactly_too_many_val…_(a53a2aec02bc999).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
unpacking.md_-_Unpacking_-_Right_hand_side_not_…_(fae6e2d526396252).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
unpacking.md_-_Unpacking_-_Too_few_values_to_un…_(cef19e6b2b58e6a3).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
unresolved_import.md_-_Unresolved_import_di…_-_An_unresolvable_impo…_(72d090df51ea97b8).snap [ty] Add note to `unresolved-import` hinting to users to configure their Python environment (#18207) 2025-05-19 17:24:25 -04:00
unresolved_import.md_-_Unresolved_import_di…_-_Using_`from`_with_a_…_(12d4a70b7fc67cc6).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
unresolved_import.md_-_Unresolved_import_di…_-_Using_`from`_with_an…_(6cff507dc64a1bff).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
unresolved_import.md_-_Unresolved_import_di…_-_Using_`from`_with_an…_(9da56616d6332a83).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
unresolved_import.md_-_Unresolved_import_di…_-_Using_`from`_with_an…_(9fa713dfa17cc404).snap [ty] Add note to `unresolved-import` hinting to users to configure their Python environment (#18207) 2025-05-19 17:24:25 -04:00
unresolved_import.md_-_Unresolved_import_di…_-_Using_`from`_with_to…_(4b8ba6ee48180cdd).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
unresolved_reference…_-_Diagnostics_for_unre…_-_New_builtin_used_on_…_(51edda0b1aebc2bf).snap [ty] Tell the user why we inferred the Python version we inferred (#18082) 2025-05-21 11:06:27 -04:00
unsupported_bool_con…_-_Different_ways_that_…_-_Has_a_`__bool__`_att…_(2721d40bf12fe8b7).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
unsupported_bool_con…_-_Different_ways_that_…_-_Has_a_`__bool__`_met…_(15636dc4074e5335).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
unsupported_bool_con…_-_Different_ways_that_…_-_Has_a_`__bool__`_met…_(ce8b8da49eaf4cda).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
unsupported_bool_con…_-_Different_ways_that_…_-_Part_of_a_union_wher…_(7cca8063ea43c1a).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00
version_related_synt…_-_Version-related_synt…_-_`match`_statement_-_Before_3.10_(2545eaa83b635b8b).snap [ty] Shorten snapshot names (#18039) 2025-05-13 18:43:19 +02:00