Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Pierre Sassoulas <[email protected]>
  • Loading branch information
jacobtylerwalls and Pierre-Sassoulas authored Apr 16, 2024
1 parent d40710e commit b362668
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 14 deletions.
8 changes: 4 additions & 4 deletions doc/data/messages/p/possibly-used-before-assignment/bad.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
def func(value):
if value:
has_value = True
print(has_value) # [possibly-used-before-assignment]
def check_lunchbox(items: list[str]):
if not items:
empty = True
print(empty) # [possibly-used-before-assignment]
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ If you rely on a pattern like:

you may be concerned that ``possibly-used-before-assignment`` is not totally useful
in this instance. However, consider that pylint, as a static analysis tool, does
not know if ``guarded()`` is deterministic, has side effects, or talks to
not know if ``guarded()`` is deterministic or talks to
a database. (Likewise, for ``guarded`` instead of ``guarded()``, any other
part of your program may have changed its value in the meantime.)
10 changes: 5 additions & 5 deletions doc/data/messages/p/possibly-used-before-assignment/good.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
def func(value):
value = False
if value:
has_value = True
print(has_value)
def check_lunchbox(items: list[str]):
empty = False
if not items:
empty = True
print(empty)
2 changes: 1 addition & 1 deletion pylint/checkers/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ def _inferred_to_define_name_raise_or_return(
if not isinstance(node, nodes.If):
return False

# Be permissive if there is a break or continue
# Be permissive if there is a break or a continue
if any(node.nodes_of_class(nodes.Break, nodes.Continue)):
return True

Expand Down
4 changes: 1 addition & 3 deletions tests/test_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ class LintTestUsingModule:
output: str | None = None

def _test_functionality(self) -> None:
tocheck = []
if self.module:
tocheck = [self.package + "." + self.module]
tocheck = [self.package + "." + self.module] if self.module else []
if self.depends:
tocheck += [
self.package + f".{name.replace('.py', '')}" for name, _ in self.depends
Expand Down

0 comments on commit b362668

Please sign in to comment.