Skip to content

Commit

Permalink
Remove temporary files
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Jan 3, 2024
1 parent 14476ab commit f9e2d2b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 25 deletions.
5 changes: 1 addition & 4 deletions crates/ruff_linter/src/rules/flake8_annotations/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,7 @@ pub(crate) fn auto_return_type(function: &ast::StmtFunctionDef) -> Option<AutoPy
// if x > 0:
// return 1
// ```
if terminal == Terminal::ConditionalReturn
|| terminal == Terminal::None
|| terminal == Terminal::Implicit
{
if terminal.has_implicit_return() {
return_type = return_type.union(ResolvedPythonType::Atom(PythonType::None));
}

Expand Down
33 changes: 19 additions & 14 deletions crates/ruff_python_semantic/src/analyze/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ impl Terminal {
Self::from_body(&function.body)
}

/// Returns `true` if the [`Terminal`] behavior includes at least one `return` path.
pub fn has_any_return(self) -> bool {
matches!(
self,
Self::Return | Self::Explicit | Self::ConditionalReturn
)
}

/// Returns `true` if the [`Terminal`] behavior includes at least one implicit `return` path.
pub fn has_implicit_return(self) -> bool {
matches!(self, Self::None | Self::Implicit | Self::ConditionalReturn)
}

/// Returns the [`Terminal`] behavior of the body, if it can be determined.
fn from_body(stmts: &[Stmt]) -> Terminal {
let mut terminal = Terminal::None;
Expand Down Expand Up @@ -58,7 +71,7 @@ impl Terminal {
if elif_else_clauses.iter().any(|clause| clause.test.is_none()) {
// And all branches return, then the `if` statement returns.
terminal = terminal.and_then(branch_terminal);
} else if branch_terminal.has_return() {
} else if branch_terminal.has_any_return() {
// Otherwise, if any branch returns, we know this can't be a
// non-returning function.
terminal = terminal.and_then(Terminal::ConditionalReturn);
Expand All @@ -77,7 +90,7 @@ impl Terminal {
} else {
// Otherwise, if any branch returns, we know this can't be a
// non-returning function.
if branch_terminal.has_return() {
if branch_terminal.has_any_return() {
terminal = terminal.and_then(Terminal::ConditionalReturn);
}
}
Expand All @@ -91,7 +104,7 @@ impl Terminal {
}) => {
// If the body returns, then this can't be a non-returning function.
let body_terminal = Self::from_body(body);
if body_terminal.has_return() {
if body_terminal.has_any_return() {
terminal = terminal.and_then(Terminal::ConditionalReturn);
}

Expand All @@ -109,7 +122,7 @@ impl Terminal {

if orelse.is_empty() {
// If there's no `else`, we may fall through.
if branch_terminal.has_return() {
if branch_terminal.has_any_return() {
terminal = terminal.and_then(Terminal::ConditionalReturn);
}
} else {
Expand Down Expand Up @@ -137,14 +150,6 @@ impl Terminal {
}
}

/// Returns `true` if the [`Terminal`] behavior includes at least one `return` path.
fn has_return(self) -> bool {
matches!(
self,
Self::Return | Self::Explicit | Self::ConditionalReturn
)
}

/// Combine two [`Terminal`] operators, with one appearing after the other.
fn and_then(self, other: Self) -> Self {
match (self, other) {
Expand Down Expand Up @@ -238,15 +243,15 @@ fn sometimes_breaks(stmts: &[Stmt]) -> bool {
for stmt in stmts {
match stmt {
Stmt::For(ast::StmtFor { body, orelse, .. }) => {
if Terminal::from_body(body).has_return() {
if Terminal::from_body(body).has_any_return() {
return false;
}
if sometimes_breaks(orelse) {
return true;
}
}
Stmt::While(ast::StmtWhile { body, orelse, .. }) => {
if Terminal::from_body(body).has_return() {
if Terminal::from_body(body).has_any_return() {
return false;
}
if sometimes_breaks(orelse) {
Expand Down
7 changes: 0 additions & 7 deletions foo.py

This file was deleted.

0 comments on commit f9e2d2b

Please sign in to comment.