[ty] Link to Callable __name__ FAQ directly from unresolved-attribute diagnostic (#22437)

This commit is contained in:
Alex Waygood
2026-01-07 13:22:53 +00:00
committed by GitHub
parent 266a7bc4c5
commit 1a7f53022a
2 changed files with 12 additions and 1 deletions

View File

@@ -2,7 +2,6 @@
source: crates/ty_test/src/lib.rs
expression: snapshot
---
---
mdtest name: attributes.md - Attributes - Diagnostic for function attribute accessed on `Callable` type
mdtest path: crates/ty_python_semantic/resources/mdtest/attributes.md
@@ -32,6 +31,7 @@ error[unresolved-attribute]: Object of type `(...) -> Unknown` has no attribute
5 | x.__annotate__ # error: [unresolved-attribute]
|
help: Function objects have a `__name__` attribute, but not all callable objects are functions
help: See this FAQ for more information: <https://docs.astral.sh/ty/reference/typing-faq/#why-does-ty-say-callable-has-no-attribute-__name__>
info: rule `unresolved-attribute` is enabled by default
```
@@ -46,6 +46,7 @@ error[unresolved-attribute]: Object of type `(...) -> Unknown` has no attribute
| ^^^^^^^^^^^^^^
|
help: Function objects have an `__annotate__` attribute, but not all callable objects are functions
help: See this FAQ for more information: <https://docs.astral.sh/ty/reference/typing-faq/#why-does-ty-say-callable-has-no-attribute-__name__>
info: rule `unresolved-attribute` is enabled by default
```

View File

@@ -10115,6 +10115,16 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
""
},
));
// without the <> around the URL, if you double click on the URL in the terminal it tries to load
// https://docs.astral.sh/ty/reference/typing-faq/#why-does-ty-say-callable-has-no-attribute-__name
// (without the __ suffix at the end of the URL). That doesn't exist, so the page loaded in the
// browser opens at the top of the FAQs page instead of taking you directly to the relevant FAQ.
diagnostic.help(
"See this FAQ for more information: \
<https://docs.astral.sh/ty/reference/typing-faq/\
#why-does-ty-say-callable-has-no-attribute-__name__>",
);
} else {
hint_if_stdlib_attribute_exists_on_other_versions(
db,