Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/ruff_db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ mod tests {
}

fn python_version(&self) -> ruff_python_ast::PythonVersion {
ruff_python_ast::PythonVersion::latest()
ruff_python_ast::PythonVersion::latest_ty()
}
}

Expand Down
4 changes: 4 additions & 0 deletions crates/ruff_python_ast/src/python_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ impl PythonVersion {
Self::PY313
}

pub const fn latest_ty() -> Self {
Self::PY313
}

Comment on lines +62 to +65
Copy link
Member Author

Choose a reason for hiding this comment

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

I added this as a precaution that we don't accidentally bump the Python version in ty when bumping the version for ruff

pub const fn as_tuple(self) -> (u8, u8) {
(self.major, self.minor)
}
Expand Down
75 changes: 75 additions & 0 deletions crates/ty/tests/cli.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use anyhow::Context;
use insta::internals::SettingsBindDropGuard;
use insta_cmd::{assert_cmd_snapshot, get_cargo_bin};
use ruff_python_ast::PythonVersion;
use std::fmt::Write;
use std::path::{Path, PathBuf};
use std::process::Command;
Expand Down Expand Up @@ -1263,6 +1264,80 @@ fn can_handle_large_binop_expressions() -> anyhow::Result<()> {
Ok(())
}

#[test]
fn defaults_to_a_new_python_version() -> anyhow::Result<()> {
let case = TestCase::with_files([
(
"ty.toml",
&*format!(
r#"
[environment]
python-version = "{}"
python-platform = "linux"
"#,
PythonVersion::default()
),
),
(
"main.py",
r#"
import os

os.grantpt(1) # only available on unix, Python 3.13 or newer
"#,
),
])?;

assert_cmd_snapshot!(case.command(), @r"
success: false
exit_code: 1
----- stdout -----
error: lint:unresolved-attribute: Type `<module 'os'>` has no attribute `grantpt`
--> main.py:4:1
|
2 | import os
3 |
4 | os.grantpt(1) # only available on unix, Python 3.13 or newer
| ^^^^^^^^^^
|
info: `lint:unresolved-attribute` is enabled by default

Found 1 diagnostic

----- stderr -----
");

// Use default (which should be latest supported)
let case = TestCase::with_files([
(
"ty.toml",
r#"
[environment]
python-platform = "linux"
"#,
),
(
"main.py",
r#"
import os

os.grantpt(1) # only available on unix, Python 3.13 or newer
"#,
),
])?;

assert_cmd_snapshot!(case.command(), @r"
success: true
exit_code: 0
----- stdout -----
All checks passed!

----- stderr -----
");

Ok(())
}

struct TestCase {
_temp_dir: TempDir,
_settings_scope: SettingsBindDropGuard,
Expand Down
2 changes: 1 addition & 1 deletion crates/ty_ide/src/inlay_hints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ mod tests {
Program::from_settings(
&db,
ProgramSettings {
python_version: PythonVersion::latest(),
python_version: PythonVersion::latest_ty(),
python_platform: PythonPlatform::default(),
search_paths: SearchPathSettings {
extra_paths: vec![],
Expand Down
2 changes: 1 addition & 1 deletion crates/ty_ide/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ mod tests {
Program::from_settings(
&db,
ProgramSettings {
python_version: PythonVersion::latest(),
python_version: PythonVersion::latest_ty(),
python_platform: PythonPlatform::default(),
search_paths: SearchPathSettings {
extra_paths: vec![],
Expand Down
2 changes: 1 addition & 1 deletion crates/ty_project/src/metadata/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl Options {
.environment
.as_ref()
.and_then(|env| env.python_version.as_deref().copied())
.unwrap_or_default();
.unwrap_or(PythonVersion::latest_ty());
let python_platform = self
.environment
.as_ref()
Expand Down
2 changes: 1 addition & 1 deletion crates/ty_project/src/metadata/pyproject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl Project {
let major =
u8::try_from(major).map_err(|_| ResolveRequiresPythonError::TooLargeMajor(major))?;
let minor =
u8::try_from(minor).map_err(|_| ResolveRequiresPythonError::TooLargeMajor(minor))?;
u8::try_from(minor).map_err(|_| ResolveRequiresPythonError::TooLargeMinor(minor))?;

Ok(Some(
requires_python
Expand Down
2 changes: 1 addition & 1 deletion crates/ty_python_semantic/src/types/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2734,7 +2734,7 @@ mod tests {

Program::get(&db)
.set_python_version(&mut db)
.to(PythonVersion::latest());
.to(PythonVersion::latest_ty());

for class in KnownClass::iter() {
assert_ne!(
Expand Down
Loading