mirror of
https://github.com/astral-sh/ruff.git
synced 2025-11-20 12:35:40 +00:00
[ty] Refactor: Use let-chains in a few places (#20985)
This commit is contained in:
parent
44e678a222
commit
54cd9d889d
4 changed files with 66 additions and 70 deletions
|
|
@ -527,8 +527,8 @@ impl<'db> SemanticIndex<'db> {
|
|||
break;
|
||||
}
|
||||
if !ancestor_scope.is_eager() {
|
||||
if let PlaceExprRef::Symbol(symbol) = expr {
|
||||
if let Some(place_id) =
|
||||
if let PlaceExprRef::Symbol(symbol) = expr
|
||||
&& let Some(place_id) =
|
||||
self.place_tables[enclosing_scope].symbol_id(symbol.name())
|
||||
{
|
||||
let key = EnclosingSnapshotKey {
|
||||
|
|
@ -542,7 +542,6 @@ impl<'db> SemanticIndex<'db> {
|
|||
.enclosing_snapshot(*id, key.nested_laziness);
|
||||
}
|
||||
}
|
||||
}
|
||||
return EnclosingSnapshotResult::NoLongerInEagerContext;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -622,11 +622,11 @@ impl CondaEnvironmentKind {
|
|||
/// the active environment name, not a constant base environment name.
|
||||
fn from_prefix_path(system: &dyn System, path: &SystemPath) -> Self {
|
||||
// If `_CONDA_ROOT` is set and matches `CONDA_PREFIX`, it's the base environment.
|
||||
if let Ok(conda_root) = system.env_var(EnvVars::CONDA_ROOT) {
|
||||
if path.as_str() == conda_root {
|
||||
if let Ok(conda_root) = system.env_var(EnvVars::CONDA_ROOT)
|
||||
&& path.as_str() == conda_root
|
||||
{
|
||||
return Self::Base;
|
||||
}
|
||||
}
|
||||
|
||||
// Next, we'll use a heuristic based on `CONDA_DEFAULT_ENV`
|
||||
let Ok(current_env) = system.env_var(EnvVars::CONDA_DEFAULT_ENV) else {
|
||||
|
|
|
|||
|
|
@ -616,11 +616,11 @@ impl<'db> FunctionLiteral<'db> {
|
|||
// We only include an implementation (i.e. a definition not decorated with `@overload`) if
|
||||
// it's the only definition.
|
||||
let (overloads, implementation) = self.overloads_and_implementation(db);
|
||||
if let Some(implementation) = implementation {
|
||||
if overloads.is_empty() {
|
||||
if let Some(implementation) = implementation
|
||||
&& overloads.is_empty()
|
||||
{
|
||||
return CallableSignature::single(implementation.signature(db));
|
||||
}
|
||||
}
|
||||
|
||||
CallableSignature::from_overloads(overloads.iter().map(|overload| overload.signature(db)))
|
||||
}
|
||||
|
|
@ -1048,8 +1048,8 @@ fn is_instance_truthiness<'db>(
|
|||
class: ClassLiteral<'db>,
|
||||
) -> Truthiness {
|
||||
let is_instance = |ty: &Type<'_>| {
|
||||
if let Type::NominalInstance(instance) = ty {
|
||||
if instance
|
||||
if let Type::NominalInstance(instance) = ty
|
||||
&& instance
|
||||
.class(db)
|
||||
.iter_mro(db)
|
||||
.filter_map(ClassBase::into_class)
|
||||
|
|
@ -1060,7 +1060,6 @@ fn is_instance_truthiness<'db>(
|
|||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
false
|
||||
};
|
||||
|
||||
|
|
@ -1642,8 +1641,9 @@ impl KnownFunction {
|
|||
|
||||
match second_argument {
|
||||
Type::ClassLiteral(class) => {
|
||||
if let Some(protocol_class) = class.into_protocol_class(db) {
|
||||
if !protocol_class.is_runtime_checkable(db) {
|
||||
if let Some(protocol_class) = class.into_protocol_class(db)
|
||||
&& !protocol_class.is_runtime_checkable(db)
|
||||
{
|
||||
report_runtime_check_against_non_runtime_checkable_protocol(
|
||||
context,
|
||||
call_expression,
|
||||
|
|
@ -1651,7 +1651,6 @@ impl KnownFunction {
|
|||
self,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if self == KnownFunction::IsInstance {
|
||||
overload.set_return_type(
|
||||
|
|
|
|||
|
|
@ -326,8 +326,8 @@ fn validate_from_dict_literal<'db, 'ast>(
|
|||
if let ast::Expr::Dict(dict_expr) = &arguments.args[0] {
|
||||
// Validate dict entries
|
||||
for dict_item in &dict_expr.items {
|
||||
if let Some(ref key_expr) = dict_item.key {
|
||||
if let ast::Expr::StringLiteral(ast::ExprStringLiteral {
|
||||
if let Some(ref key_expr) = dict_item.key
|
||||
&& let ast::Expr::StringLiteral(ast::ExprStringLiteral {
|
||||
value: key_value, ..
|
||||
}) = key_expr
|
||||
{
|
||||
|
|
@ -349,7 +349,6 @@ fn validate_from_dict_literal<'db, 'ast>(
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
provided_keys
|
||||
}
|
||||
|
|
@ -404,9 +403,9 @@ pub(super) fn validate_typed_dict_dict_literal<'db>(
|
|||
|
||||
// Validate each key-value pair in the dictionary literal
|
||||
for item in &dict_expr.items {
|
||||
if let Some(key_expr) = &item.key {
|
||||
let key_ty = expression_type_fn(key_expr);
|
||||
if let Type::StringLiteral(key_str) = key_ty {
|
||||
if let Some(key_expr) = &item.key
|
||||
&& let Type::StringLiteral(key_str) = expression_type_fn(key_expr)
|
||||
{
|
||||
let key_str = key_str.value(context.db());
|
||||
provided_keys.insert(key_str);
|
||||
|
||||
|
|
@ -424,7 +423,6 @@ pub(super) fn validate_typed_dict_dict_literal<'db>(
|
|||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
valid &= validate_typed_dict_required_keys(context, typed_dict, &provided_keys, error_node);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue