[ty] Improve diagnostics if the user attempts to import a stdlib module that does not exist on their configured Python version (#18403)

This commit is contained in:
Alex Waygood
2025-06-02 11:52:26 +01:00
committed by GitHub
parent 384e80ec80
commit e2d96df501
8 changed files with 300 additions and 38 deletions

View File

@@ -176,3 +176,32 @@ emitted for the `import from` statement:
# error: [unresolved-import]
from does_not_exist import foo, bar, baz
```
## Attempting to import a stdlib module that's not yet been added
<!-- snapshot-diagnostics -->
```toml
[environment]
python-version = "3.10"
```
```py
import tomllib # error: [unresolved-import]
from string.templatelib import Template # error: [unresolved-import]
from importlib.resources import abc # error: [unresolved-import]
```
## Attempting to import a stdlib module that was previously removed
<!-- snapshot-diagnostics -->
```toml
[environment]
python-version = "3.13"
```
```py
import aifc # error: [unresolved-import]
from distutils import sysconfig # error: [unresolved-import]
```