[red-knot] Default python-platform to current platform (#17183)

## Summary

As discussed in https://github.com/astral-sh/ruff/issues/16983 and
"mitigate" said issue for the alpha.

This PR changes the default for `PythonPlatform` to be the current
platform rather than `all`.

I'm not sure if we should be as sophisticated as supporting `ios` and
`android` as defaults but it was easy...

## Test Plan

Updated Markdown tests.

---------

Co-authored-by: David Peter <mail@david-peter.de>
This commit is contained in:
Micha Reiser 2025-04-09 12:05:18 +02:00 committed by GitHub
parent 00e00b9ad6
commit 8249a72412
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 49 additions and 52 deletions

View file

@ -1,7 +1,7 @@
use std::fmt::{Display, Formatter};
/// The target platform to assume when resolving types.
#[derive(Debug, Clone, Default, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(
feature = "serde",
derive(serde::Serialize, serde::Deserialize),
@ -9,7 +9,6 @@ use std::fmt::{Display, Formatter};
)]
pub enum PythonPlatform {
/// Do not make any assumptions about the target platform.
#[default]
All,
/// Assume a specific target platform like `linux`, `darwin` or `win32`.
@ -39,6 +38,22 @@ impl Display for PythonPlatform {
}
}
impl Default for PythonPlatform {
fn default() -> Self {
if cfg!(target_os = "windows") {
PythonPlatform::Identifier("win32".to_string())
} else if cfg!(target_os = "macos") {
PythonPlatform::Identifier("darwin".to_string())
} else if cfg!(target_os = "android") {
PythonPlatform::Identifier("android".to_string())
} else if cfg!(target_os = "ios") {
PythonPlatform::Identifier("ios".to_string())
} else {
PythonPlatform::Identifier("linux".to_string())
}
}
}
#[cfg(feature = "schemars")]
mod schema {
use crate::PythonPlatform;