[ty] Add support for re-exports and `__all__` to auto-import

This commit (mostly) re-implements the support for `__all__` in
ty-proper, but inside the auto-import AST scanner.

When `__all__` isn't present in a module, we fall back to conventions to
determine whether a symbol is exported or not:
https://docs.python.org/3/library/index.html

However, in keeping with current practice for non-auto-import
completions, we continue to provide sunder and dunder names as
re-exports.

When `__all__` is present, we respect it strictly. That is, a symbol is
exported *if and only if* it's in `__all__`. This is somewhat stricter
than pylance seemingly is. I felt like it was a good idea to start here,
and we can relax it based on user demand (perhaps through a setting).
This commit is contained in:
Andrew Gallant 2025-11-25 14:03:19 -05:00 committed by Andrew Gallant
parent 086f1e0b89
commit 8c72b296c9
5 changed files with 1293 additions and 31 deletions

File diff suppressed because it is too large Load Diff

View File

@ -6,7 +6,7 @@ expression: completions
{ {
"label": "Literal (import typing)", "label": "Literal (import typing)",
"kind": 6, "kind": 6,
"sortText": " 50", "sortText": " 58",
"insertText": "Literal", "insertText": "Literal",
"additionalTextEdits": [ "additionalTextEdits": [
{ {
@ -27,7 +27,7 @@ expression: completions
{ {
"label": "LiteralString (import typing)", "label": "LiteralString (import typing)",
"kind": 6, "kind": 6,
"sortText": " 51", "sortText": " 59",
"insertText": "LiteralString", "insertText": "LiteralString",
"additionalTextEdits": [ "additionalTextEdits": [
{ {

View File

@ -6,7 +6,7 @@ expression: completions
{ {
"label": "Literal (import typing)", "label": "Literal (import typing)",
"kind": 6, "kind": 6,
"sortText": " 50", "sortText": " 58",
"insertText": "Literal", "insertText": "Literal",
"additionalTextEdits": [ "additionalTextEdits": [
{ {
@ -27,7 +27,7 @@ expression: completions
{ {
"label": "LiteralString (import typing)", "label": "LiteralString (import typing)",
"kind": 6, "kind": 6,
"sortText": " 51", "sortText": " 59",
"insertText": "LiteralString", "insertText": "LiteralString",
"additionalTextEdits": [ "additionalTextEdits": [
{ {

View File

@ -6,7 +6,7 @@ expression: completions
{ {
"label": "Literal (import typing)", "label": "Literal (import typing)",
"kind": 6, "kind": 6,
"sortText": " 50", "sortText": " 58",
"insertText": "Literal", "insertText": "Literal",
"additionalTextEdits": [ "additionalTextEdits": [
{ {
@ -27,7 +27,7 @@ expression: completions
{ {
"label": "LiteralString (import typing)", "label": "LiteralString (import typing)",
"kind": 6, "kind": 6,
"sortText": " 51", "sortText": " 59",
"insertText": "LiteralString", "insertText": "LiteralString",
"additionalTextEdits": [ "additionalTextEdits": [
{ {

View File

@ -6,7 +6,7 @@ expression: completions
{ {
"label": "Literal (import typing)", "label": "Literal (import typing)",
"kind": 6, "kind": 6,
"sortText": " 50", "sortText": " 58",
"insertText": "Literal", "insertText": "Literal",
"additionalTextEdits": [ "additionalTextEdits": [
{ {
@ -27,7 +27,7 @@ expression: completions
{ {
"label": "LiteralString (import typing)", "label": "LiteralString (import typing)",
"kind": 6, "kind": 6,
"sortText": " 51", "sortText": " 59",
"insertText": "LiteralString", "insertText": "LiteralString",
"additionalTextEdits": [ "additionalTextEdits": [
{ {