Skip to content

Commit

Permalink
Help pylint with drenv.commands
Browse files Browse the repository at this point in the history
Looks like recent change in pylint trigger this incorrect report:

    drenv/commands.py:234:28: E0606: Possibly using variable
    'input_view' before assignment (possibly-used-before-assignment)

This cannot happen since we don't register proc.stdin if input is None,
so when we reach this block input_view is assigned. However disabling
the check risk missing a real issue in that block.

Lets change the code so pylint can understand it better. This also make
it easier to understand for humans. The cost is negligible, adding 2
temporary variables even when they are never used.

Signed-off-by: Nir Soffer <nsoffer@redhat.com>
  • Loading branch information
nirs authored and ShyamsundarR committed May 15, 2024
1 parent 358a919 commit 797c1a8
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion test/drenv/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,17 @@ def stream(proc, input=None, bufsize=32 << 10, timeout=None):
except BrokenPipeError:
pass

# Use only if input is not None, but it helps pylint.
input_view = ""
input_offset = 0

with _Selector() as sel:
for f, src in (proc.stdout, OUT), (proc.stderr, ERR):
if f and not f.closed:
sel.register(f, selectors.EVENT_READ, src)
if input:
sel.register(proc.stdin, selectors.EVENT_WRITE)
input_view = memoryview(input.encode())
input_offset = 0

while sel.get_map():
remaining = _remaining_time(deadline)
Expand Down

0 comments on commit 797c1a8

Please sign in to comment.