-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Formatter: Add SourceType to context to enable special formatting for stub files #6331
Conversation
Current dependencies on/for this PR:
This comment was auto-generated by Graphite. |
#[derive(Clone, Debug)] | ||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] | ||
pub enum SourceType { | ||
/// A `.py` file | ||
Py, | ||
/// A `.pyi` file | ||
Pyi, | ||
} | ||
|
||
impl SourceType { | ||
pub fn from_path(path: &Path) -> Option<Self> { | ||
match path.extension().and_then(OsStr::to_str) { | ||
Some("py") => Some(Self::Py), | ||
Some("pyi") => Some(Self::Pyi), | ||
_ => None, | ||
} | ||
} | ||
} | ||
|
||
impl Default for SourceType { | ||
fn default() -> Self { | ||
Self::Py | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#5552 introduces a new PySourceType
. What do you think of moving PySourceType
to ruff_python_ast
and re-using it here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-.- i was searching for this and couldn't find it, thanks
PR Check ResultsEcosystem✅ ecosystem check detected no changes. BenchmarkLinux
Windows
|
@dhruvmanila I've copied most of |
Co-authored-by: Micha Reiser <micha@reiser.io>
c27ba8d
to
fcc465c
Compare
Hey, thanks for informing. I'll rebase it, no problem :) |
Summary This adds the information whether we're in a .py python source file or in a .pyi stub file to enable people working on #5822 and related issues.
I'm not completely happy with
Default
for something that depends on the input.Test Plan None, this is currently unused, i'm leaving this to first implementation of stub file specific formatting.