Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 4 additions & 3 deletions astroid/brain/brain_builtin_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@ def _infer_copy_method(

def _is_str_format_call(node: nodes.Call) -> bool:
"""Catch calls to str.format()."""
if not isinstance(node.func, nodes.Attribute) or not node.func.attrname == "format":
if not (isinstance(node.func, nodes.Attribute) and node.func.attrname == "format"):
return False

if isinstance(node.func.expr, nodes.Name):
Expand All @@ -1018,8 +1018,9 @@ def _infer_str_format_call(

value: nodes.Const
if isinstance(node.func.expr, nodes.Name):
if not (inferred := util.safe_infer(node.func.expr)) or not isinstance(
inferred, nodes.Const
if not (
(inferred := util.safe_infer(node.func.expr))
and isinstance(inferred, nodes.Const)
):
return iter([util.Uninferable])
value = inferred
Expand Down
7 changes: 4 additions & 3 deletions astroid/brain/brain_dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def is_decorated_with_dataclass(
node: nodes.ClassDef, decorator_names: frozenset[str] = DATACLASSES_DECORATORS
) -> bool:
"""Return True if a decorated node has a `dataclass` decorator applied."""
if not isinstance(node, nodes.ClassDef) or not node.decorators:
if not (isinstance(node, nodes.ClassDef) and node.decorators):
return False

return any(
Expand Down Expand Up @@ -112,8 +112,9 @@ def _get_dataclass_attributes(
If init is True, also include InitVars.
"""
for assign_node in node.body:
if not isinstance(assign_node, nodes.AnnAssign) or not isinstance(
assign_node.target, nodes.AssignName
if not (
isinstance(assign_node, nodes.AnnAssign)
and isinstance(assign_node.target, nodes.AssignName)
):
continue

Expand Down
2 changes: 1 addition & 1 deletion astroid/brain/brain_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def infer_type_sub(node, context: InferenceContext | None = None):
:rtype: nodes.NodeNG
"""
node_scope, _ = node.scope().lookup("type")
if not isinstance(node_scope, nodes.Module) or node_scope.qname() != "builtins":
if not (isinstance(node_scope, nodes.Module) and node_scope.qname() == "builtins"):
raise UseInferenceDefault()
class_src = """
class type:
Expand Down
16 changes: 8 additions & 8 deletions astroid/brain/brain_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,10 @@ def infer_typing_alias(

# TODO: evaluate if still necessary when Py3.12 is minimum
"""
if (
not isinstance(node.parent, nodes.Assign)
or not len(node.parent.targets) == 1
or not isinstance(node.parent.targets[0], nodes.AssignName)
if not (
isinstance(node.parent, nodes.Assign)
and len(node.parent.targets) == 1
and isinstance(node.parent.targets[0], nodes.AssignName)
):
raise UseInferenceDefault
try:
Expand Down Expand Up @@ -408,10 +408,10 @@ def infer_typing_cast(
func = next(node.func.infer(context=ctx))
except (InferenceError, StopIteration) as exc:
raise UseInferenceDefault from exc
if (
not isinstance(func, nodes.FunctionDef)
or func.qname() != "typing.cast"
or len(node.args) != 2
if not (
isinstance(func, nodes.FunctionDef)
and func.qname() == "typing.cast"
and len(node.args) == 2
):
raise UseInferenceDefault

Expand Down
2 changes: 1 addition & 1 deletion astroid/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def object_type(
types = set(_object_type(node, context))
except InferenceError:
return util.Uninferable
if len(types) > 1 or not types:
if len(types) != 1:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice !

return util.Uninferable
return next(iter(types))

Expand Down
11 changes: 6 additions & 5 deletions astroid/nodes/scoped_nodes/scoped_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1223,7 +1223,7 @@ def extra_decorators(self) -> list[node_classes.Call]:
The property will return all the callables that are used for
decoration.
"""
if not self.parent or not isinstance(frame := self.parent.frame(), ClassDef):
if not (self.parent and isinstance(frame := self.parent.frame(), ClassDef)):
return []

decorators: list[node_classes.Call] = []
Expand Down Expand Up @@ -1517,7 +1517,7 @@ def _infer(
) -> Generator[objects.Property | FunctionDef, None, InferenceErrorInfo]:
from astroid import objects # pylint: disable=import-outside-toplevel

if not self.decorators or not bases._is_property(self):
if not (self.decorators and bases._is_property(self)):
yield self
return InferenceErrorInfo(node=self, context=context)

Expand Down Expand Up @@ -2725,9 +2725,10 @@ def _islots(self):
for elt in values:
try:
for inferred in elt.infer():
if not isinstance(
inferred, node_classes.Const
) or not isinstance(inferred.value, str):
if not (
isinstance(inferred, node_classes.Const)
and isinstance(inferred.value, str)
):
continue
if not inferred.value:
continue
Expand Down
2 changes: 1 addition & 1 deletion astroid/protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def _multiply_seq_by_int(
context: InferenceContext,
) -> _TupleListNodeT:
node = self.__class__(parent=opnode)
if value <= 0 or not self.elts:
if not (value > 0 and self.elts):
node.elts = []
return node
if len(self.elts) * value > 1e8:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_get_relative_base_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def setUp(self):
self.cwd = os.getcwd()

def _run_relative_path_test(self, target, base, expected):
if not target or not base:
if not (target and base):
result = None
else:
base_dir = os.path.join(self.cwd, base)
Expand Down