8000 Use `Self` where possible by ShaharNaveh · Pull Request #5892 · RustPython/RustPython · GitHub
[go: up one dir, main page]

Skip to content

Use Self where possible #5892

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

Merged
merged 11 commits into from
Jul 4, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Use Self in derive-impl
  • Loading branch information
ShaharNaveh committed Jul 3, 2025
commit 211252f1972bdd36eff85a515f7f4a4e8595a503
4 changes: 2 additions & 2 deletions derive-impl/src/compile_bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ impl CompilationSource {
}

impl PyCompileArgs {
fn parse(input: TokenStream, allow_dir: bool) -> Result<PyCompileArgs, Diagnostic> {
fn parse(input: TokenStream, allow_dir: bool) -> Result<Self, Diagnostic> {
let mut module_name = None;
let mut mode = None;
let mut source: Option<CompilationSource> = None;
Expand Down Expand Up @@ -307,7 +307,7 @@ impl PyCompileArgs {
)
})?;

Ok(PyCompileArgs {
Ok(Self {
source,
mode: mode.unwrap_or(Mode::Exec),
module_name: module_name.unwrap_or_else(|| "frozen".to_owned()),
Expand Down
16 changes: 8 additions & 8 deletions derive-impl/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,29 +75,29 @@ enum Repr {
}

impl Diagnostic {
pub fn error<T: Into<String>>(text: T) -> Diagnostic {
Diagnostic {
pub fn error<T: Into<String>>(text: T) -> Self {
Self {
inner: Repr::Single {
text: text.into(),
span: None,
},
}
}

pub(crate) fn spans_error<T: Into<String>>(spans: (Span, Span), text: T) -> Diagnostic {
Diagnostic {
pub(crate) fn spans_error<T: Into<String>>(spans: (Span, Span), text: T) -> Self {
Self {
inner: Repr::Single {
text: text.into(),
span: Some(spans),
},
}
}

pub fn from_vec(diagnostics: Vec<Diagnostic>) -> Result<(), Diagnostic> {
pub fn from_vec(diagnostics: Vec<Self>) -> Result<(), Self> {
if diagnostics.is_empty() {
Ok(())
} else {
Err(Diagnostic {
Err(Self {
inner: Repr::Multi { diagnostics },
})
}
Expand All @@ -113,8 +113,8 @@ impl Diagnostic {
}

impl From<Error> for Diagnostic {
fn from(err: Error) -> Diagnostic {
Diagnostic {
fn from(err: Error) -> Self {
Self {
inner: Repr::SynError(err),
}
}
Expand Down
14 changes: 7 additions & 7 deletions derive-impl/src/from_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ enum ParameterKind {
}

impl ParameterKind {
fn from_ident(ident: &Ident) -> Option<ParameterKind> {
fn from_ident(ident: &Ident) -> Option<Self> {
match ident.to_string().as_str() {
"positional" => Some(ParameterKind::PositionalOnly),
"any" => Some(ParameterKind::PositionalOrKeyword),
"named" => Some(ParameterKind::KeywordOnly),
"flatten" => Some(ParameterKind::Flatten),
"positional" => Some(Self::PositionalOnly),
"any" => Some(Self::PositionalOrKeyword),
"named" => Some(Self::KeywordOnly),
"flatten" => Some(Self::Flatten),
_ => None,
}
}
Expand All @@ -34,7 +34,7 @@ struct ArgAttribute {
type DefaultValue = Option<Expr>;

impl ArgAttribute {
fn from_attribute(attr: &Attribute) -> Option<Result<ArgAttribute>> {
fn from_attribute(attr: &Attribute) -> Option<Result<Self>> {
if !attr.path().is_ident("pyarg") {
return None;
}
Expand All @@ -52,7 +52,7 @@ impl ArgAttribute {
either 'positional', 'any', 'named', or 'flatten'.",
)
})?;
arg_attr = Some(ArgAttribute {
arg_attr = Some(Self {
name: None,
kind,
default: None,
Expand Down
0