Skip to content

[ty] Add a SupportedPythonVersion enum#24412

Merged
charliermarsh merged 1 commit intomainfrom
charlie/display-types
Apr 10, 2026
Merged

[ty] Add a SupportedPythonVersion enum#24412
charliermarsh merged 1 commit intomainfrom
charlie/display-types

Conversation

@charliermarsh
Copy link
Copy Markdown
Member

@charliermarsh charliermarsh commented Apr 5, 2026

Summary

This unifies the validation of supported Python versions between the CLI and TOML (e.g., environment.python-version) by introducing a single enum to share across them.

@charliermarsh charliermarsh added the configuration Related to settings and configuration label Apr 5, 2026
@charliermarsh charliermarsh changed the title [ty] Add a SupportedPythonVersion enum to enable JSON schema [ty] Add a SupportedPythonVersion enum Apr 5, 2026
@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot Bot commented Apr 5, 2026

Typing conformance results

No changes detected ✅

Current numbers
The percentage of diagnostics emitted that were expected errors held steady at 87.72%. The percentage of expected errors that received a diagnostic held steady at 82.85%. The number of fully passing files held steady at 74/132.

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot Bot commented Apr 5, 2026

Memory usage report

Memory usage unchanged ✅

@charliermarsh charliermarsh force-pushed the charlie/display-types branch from e039630 to 7068819 Compare April 5, 2026 01:34
@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot Bot commented Apr 5, 2026

ecosystem-analyzer results

Lint rule Added Removed Changed
invalid-await 40 0 0
invalid-return-type 1 0 0
Total 41 0 0

Changes in flaky projects detected. Raw diff output excludes flaky projects; see the HTML report for details.

Full report with detailed diff (timing results)

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot Bot commented Apr 5, 2026

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

@charliermarsh charliermarsh force-pushed the charlie/display-types branch from 7068819 to 5595025 Compare April 5, 2026 01:44
@charliermarsh charliermarsh marked this pull request as ready for review April 5, 2026 02:37
@charliermarsh charliermarsh added the ty Multi-file analysis & type inference label Apr 5, 2026
@carljm carljm assigned MichaReiser and unassigned carljm Apr 7, 2026
@carljm carljm removed their request for review April 7, 2026 05:50
Copy link
Copy Markdown
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking into this.

I think I'd prefer this not be a serde deserialization error. Validating the schema with serde (or clap) is straightforward, but it comes at the cost of ty not understanding the entire configuration if there's the slightest mistake.

It also feels overly strict to me to reject newer Python versions. What if a project wants to use the next Python version but hasn't yet had a chance to upgrade ty? In that case, I think it would be fine to emit a warning diagnostic saying that the specified Python version isn't supported.

We could accomplish this by manually implementing the validation in to_program_settings. This also ensures better error messages, where we can point users to the problematic configuration (with a code snippet) rather than a generic deserialization error.

Comment thread crates/ty_project/src/metadata/python_version.rs Outdated
Comment thread crates/ty_project/src/metadata/python_version.rs Outdated
@charliermarsh
Copy link
Copy Markdown
Member Author

It also feels overly strict to me to reject newer Python versions. What if a project wants to use the next Python version but hasn't yet had a chance to upgrade ty? In that case, I think it would be fine to emit a warning diagnostic saying that the specified Python version isn't supported.

In #24402, I changed the TOML semantics to match the CLI, which was already rejecting Python versions outside of a fixed list:

❯ cargo run -p ty check ~/workspace/foo --python-version 3.17
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.14s
     Running `target/debug/ty check /Users/crmarsh/workspace/foo --python-version 3.17`
error: invalid value '3.17' for '--python-version <VERSION>'
  [possible values: 3.7, 3.8, 3.9, 3.10, 3.11, 3.12, 3.13, 3.14, 3.15]

  tip: a similar value exists: '3.7'

For more information, try '--help'.

We could decide to change that, but my general intent was just to make it consistent with the CLI.

I think a plausible behavior would be: --python-version and environment.python-version are restricted to a specific set of versions; for requires-python, we emit a warning if you're on an unsupported version, and clamp to our closest supported version? For >=2.7 clamps to 3.7, and >=4.0 clamps to 3.15.

@MichaReiser
Copy link
Copy Markdown
Member

Oh, I wasn't aware that the CLI already behaved that way. I only saw the change in #24402. What you're suggesting sounds good to me.

@charliermarsh
Copy link
Copy Markdown
Member Author

It could have been unintentional... But yeah, my intent in that change was just to get thing into alignment. I'll follow-up with what I've suggested above.

@charliermarsh charliermarsh marked this pull request as draft April 8, 2026 11:25
@charliermarsh charliermarsh force-pushed the charlie/display-types branch from 5595025 to fd46015 Compare April 8, 2026 16:23
@charliermarsh charliermarsh changed the base branch from main to charlie/editor-version April 8, 2026 16:23
@charliermarsh charliermarsh force-pushed the charlie/editor-version branch from 1b98a90 to edffbaa Compare April 8, 2026 16:50
@charliermarsh charliermarsh force-pushed the charlie/display-types branch 2 times, most recently from a704295 to 31a9f69 Compare April 8, 2026 16:52
@charliermarsh charliermarsh force-pushed the charlie/display-types branch from 2b95754 to 333e840 Compare April 9, 2026 18:55
@charliermarsh charliermarsh force-pushed the charlie/editor-version branch from a08d136 to 482a4bc Compare April 9, 2026 19:08
@charliermarsh charliermarsh force-pushed the charlie/display-types branch from 333e840 to 409a821 Compare April 9, 2026 19:08
@charliermarsh charliermarsh force-pushed the charlie/editor-version branch from 482a4bc to 69773fc Compare April 9, 2026 19:49
@charliermarsh charliermarsh force-pushed the charlie/display-types branch from 409a821 to 1994c9b Compare April 9, 2026 19:53
@charliermarsh charliermarsh force-pushed the charlie/editor-version branch from 69773fc to d187804 Compare April 9, 2026 20:01
@charliermarsh charliermarsh force-pushed the charlie/display-types branch from 1994c9b to 134a92b Compare April 9, 2026 20:01
@charliermarsh charliermarsh force-pushed the charlie/editor-version branch from d187804 to 306c0a0 Compare April 9, 2026 20:12
@charliermarsh charliermarsh force-pushed the charlie/display-types branch from 134a92b to d3ec898 Compare April 9, 2026 20:12
@charliermarsh charliermarsh force-pushed the charlie/editor-version branch from 306c0a0 to 6ff5134 Compare April 9, 2026 20:22
@charliermarsh charliermarsh force-pushed the charlie/display-types branch from d3ec898 to 8508179 Compare April 9, 2026 20:25
@charliermarsh charliermarsh force-pushed the charlie/editor-version branch 2 times, most recently from aa3a8af to 788e7d7 Compare April 9, 2026 20:44
@charliermarsh charliermarsh force-pushed the charlie/display-types branch from 8508179 to c4526a8 Compare April 9, 2026 20:45
@charliermarsh charliermarsh force-pushed the charlie/editor-version branch from 788e7d7 to 9236531 Compare April 9, 2026 20:55
@charliermarsh charliermarsh force-pushed the charlie/display-types branch from c4526a8 to c88837e Compare April 9, 2026 21:04
@charliermarsh charliermarsh marked this pull request as ready for review April 9, 2026 21:09
@astral-sh-bot astral-sh-bot Bot requested a review from MichaReiser April 9, 2026 21:09
serde = { workspace = true }
serde_json = { workspace = true }
shellexpand = { workspace = true }
strum = { workspace = true }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, this is slightly annoying but I don't think it's worth bothering about

@charliermarsh charliermarsh force-pushed the charlie/editor-version branch 2 times, most recently from 5fe2cb8 to 364811c Compare April 10, 2026 13:27
Base automatically changed from charlie/editor-version to main April 10, 2026 13:35
@charliermarsh charliermarsh force-pushed the charlie/display-types branch from c88837e to 7e72378 Compare April 10, 2026 13:44
@charliermarsh charliermarsh enabled auto-merge (squash) April 10, 2026 13:45
@charliermarsh charliermarsh merged commit 2ad94df into main Apr 10, 2026
55 checks passed
@charliermarsh charliermarsh deleted the charlie/display-types branch April 10, 2026 13:48
carljm added a commit that referenced this pull request Apr 10, 2026
* main:
  [ty] Fix bad diagnostic range for incorrect implicit `__init_subclass__` calls (#24541)
  [ty] Add a `SupportedPythonVersion` enum (#24412)
  [ty] Ignore unsupported editor-selected Python versions (#24498)
  [ty] Add snapshots for `__init_subclass__` diagnostics (#24539)
  [ty] Minor fix in tests (#24538)
  [ty] Allow `Final` variable assignments in `__post_init__` (#24529)
  [ty] Expand test suite for assignment errors (#24537)
  [ty] Use `map`, not `__map`, as the name of the mapping parameter in `TypedDict` `__init__` methods (#24535)
  [ty] Rework logic for synthesizing `TypedDict` methods (#24534)
  [flake8-bandit] Fix S103 false positives and negatives in mask analysis (#24424)
  [ty] mdtest.py: update dependencies (#24533)
  Rename patterns and arguments source order iterator method (#24532)
  [ty] Omit invalid keyword arguments from `TypedDict` signature (#24522)
  [ty] support super() in metaclass methods (#24483)
  [ty] Synthesize `__init__` for `TypedDict` (#24476)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

configuration Related to settings and configuration ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants