[ty] Add a note to the diagnostic if a new builtin is used on an old Python version (#18068)

## Summary

If the user tries to use a new builtin on an old Python version, tell
them what Python version the builtin was added on, what our inferred
Python version is for their project, and what configuration settings
they can tweak to fix the error.

## Test Plan

Snapshots and screenshots:


![image](https://github.com/user-attachments/assets/767d570e-7af1-4e1f-98cf-50e4311db511)
This commit is contained in:
Alex Waygood 2025-05-13 10:08:04 -04:00 committed by GitHub
parent 5bf5f3682a
commit c0f22928bd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 118 additions and 54 deletions

View file

@ -0,0 +1,14 @@
# Diagnostics for unresolved references
## New builtin used on old Python version
<!-- snapshot-diagnostics -->
```toml
[environment]
python-version = "3.9"
```
```py
aiter # error: [unresolved-reference]
```

View file

@ -0,0 +1,32 @@
---
source: crates/ty_test/src/lib.rs
expression: snapshot
---
---
mdtest name: unresolved_reference.md - Diagnostics for unresolved references - New builtin used on old Python version
mdtest path: crates/ty_python_semantic/resources/mdtest/diagnostics/unresolved_reference.md
---
# Python source files
## mdtest_snippet.py
```
1 | aiter # error: [unresolved-reference]
```
# Diagnostics
```
error[unresolved-reference]: Name `aiter` used when not defined
--> src/mdtest_snippet.py:1:1
|
1 | aiter # error: [unresolved-reference]
| ^^^^^
|
info: `aiter` was added as a builtin in Python 3.10
info: The inferred target version of your project is Python 3.9
info: If using a pyproject.toml file, consider adjusting the `project.requires-python` or `tool.ty.environment.python-version` field
info: rule `unresolved-reference` is enabled by default
```