From d58ed5bd2bc5d83300f10a04eca63dc8137c098b Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Sat, 28 Aug 2021 00:40:16 +0200 Subject: [PATCH] pylint: add undefined-variable Signed-off-by: Johannes Berg Reviewed-by: Rob Browning [rlb@defaultvalue.org: add missing %s in validate_vfs_path changes] Signed-off-by: Rob Browning Tested-by: Rob Browning --- .pylintrc | 1 + lib/bup/cmd/get.py | 12 ++++++------ lib/bup/cmd/memtest.py | 1 + lib/bup/cmd/midx.py | 18 +++++++++--------- lib/bup/cmd/server.py | 2 +- lib/bup/cmd/xstat.py | 8 ++++---- lib/bup/compat.py | 7 +++++++ 7 files changed, 29 insertions(+), 20 deletions(-) diff --git a/.pylintrc b/.pylintrc index 8a6e0fc..997e09f 100644 --- a/.pylintrc +++ b/.pylintrc @@ -6,6 +6,7 @@ enable= consider-using-in, return-in-init, trailing-whitespace, + undefined-variable, unidiomatic-typecheck, unused-import, unused-wildcard-import, diff --git a/lib/bup/cmd/get.py b/lib/bup/cmd/get.py index 2b8ea1a..8629f4f 100755 --- a/lib/bup/cmd/get.py +++ b/lib/bup/cmd/get.py @@ -15,7 +15,7 @@ from bup.compat import ( ) from bup.git import get_cat_data, parse_commit, walk_object from bup.helpers import add_error, debug1, log, saved_errors -from bup.helpers import hostname, tty_width +from bup.helpers import hostname, tty_width, parse_num from bup.io import path_msg from bup.pwdgrp import userfullname, username from bup.repo import LocalRepo, RemoteRepo @@ -164,7 +164,7 @@ def parse_args(args): opt.compress = int(opt.compress) elif arg == b'--bwlimit': (opt.bwlimit,), remaining = require_n_args_or_die(1, remaining) - opt.bwlimit = long(opt.bwlimit) + opt.bwlimit = int(opt.bwlimit) elif arg.startswith(b'-') and len(arg) > 2 and arg[1] != b'-': # Try to interpret this as -xyz, i.e. "-xyz -> -x -y -z". # We do this last so that --foo -bar is valid if --foo @@ -281,11 +281,11 @@ def cleanup_vfs_path(p): return b'/' + result -def validate_vfs_path(p): +def validate_vfs_path(p, spec): if p.startswith(b'/.') \ and not p.startswith(b'/.tag/'): misuse('unsupported destination path %s in %s' - % (path_msg(dest.path), spec_msg(spec))) + % (path_msg(p), spec_msg(spec))) return p @@ -419,7 +419,7 @@ def resolve_pick(spec, src_repo, dest_repo): misuse('no destination provided for %s', spec_args) dest = find_vfs_item(spec.dest, dest_repo) if not dest: - cp = validate_vfs_path(cleanup_vfs_path(spec.dest)) + cp = validate_vfs_path(cleanup_vfs_path(spec.dest), spec) dest = default_loc._replace(path=cp) else: if not dest.type == 'branch' and not dest.path.startswith(b'/.tag/'): @@ -481,7 +481,7 @@ def resolve_replace(spec, src_repo, dest_repo): misuse('%s impossible; can only overwrite branch or tag' % spec_args) else: - cp = validate_vfs_path(cleanup_vfs_path(spec.dest)) + cp = validate_vfs_path(cleanup_vfs_path(spec.dest), spec) dest = default_loc._replace(path=cp) if not dest.path.startswith(b'/.tag/') \ and not src.type in ('branch', 'save', 'commit'): diff --git a/lib/bup/cmd/memtest.py b/lib/bup/cmd/memtest.py index 831ec54..b2027c4 100755 --- a/lib/bup/cmd/memtest.py +++ b/lib/bup/cmd/memtest.py @@ -5,6 +5,7 @@ import re, resource, sys, time from bup import git, bloom, midx, options, _helpers from bup.compat import range from bup.io import byte_stream +from bup.helpers import log _linux_warned = 0 diff --git a/lib/bup/cmd/midx.py b/lib/bup/cmd/midx.py index ba13b4a..983ba33 100755 --- a/lib/bup/cmd/midx.py +++ b/lib/bup/cmd/midx.py @@ -147,15 +147,15 @@ def _do_midx(outdir, outfilename, infilenames, prefixstr, # This is just for testing (if you enable this, don't clear inp above) - if 0: - p = midx.PackMidx(outfilename) - assert(len(p.idxnames) == len(infilenames)) - log(repr(p.idxnames) + '\n') - assert(len(p) == total) - for pe, e in p, git.idxmerge(inp, final_progress=False): - pin = next(pi) - assert(i == pin) - assert(p.exists(i)) + # if 0: + # p = midx.PackMidx(outfilename) + # assert(len(p.idxnames) == len(infilenames)) + # log(repr(p.idxnames) + '\n') + # assert(len(p) == total) + # for pe, e in p, git.idxmerge(inp, final_progress=False): + # pin = next(pi) + # assert(i == pin) + # assert(p.exists(i)) return total, outfilename diff --git a/lib/bup/cmd/server.py b/lib/bup/cmd/server.py index 824a9b2..3574428 100755 --- a/lib/bup/cmd/server.py +++ b/lib/bup/cmd/server.py @@ -228,7 +228,7 @@ def rev_list(conn, _): if rv: msg = 'git rev-list returned error %d' % rv conn.error(msg) - raise GitError(msg) + raise git.GitError(msg) conn.ok() def resolve(conn, args): diff --git a/lib/bup/cmd/xstat.py b/lib/bup/cmd/xstat.py index 246af24..5255c37 100755 --- a/lib/bup/cmd/xstat.py +++ b/lib/bup/cmd/xstat.py @@ -14,7 +14,7 @@ from bup.helpers import add_error, parse_timestamp, saved_errors, \ from bup.io import byte_stream -def parse_timestamp_arg(field, value): +def parse_timestamp_arg(o, field, value): res = str(value) # Undo autoconversion. try: res = parse_timestamp(res) @@ -50,9 +50,9 @@ def main(argv): o = options.Options(optspec) (opt, flags, remainder) = o.parse_bytes(argv[1:]) - atime_resolution = parse_timestamp_arg('atime', opt.atime_resolution) - mtime_resolution = parse_timestamp_arg('mtime', opt.mtime_resolution) - ctime_resolution = parse_timestamp_arg('ctime', opt.ctime_resolution) + atime_resolution = parse_timestamp_arg(o, 'atime', opt.atime_resolution) + mtime_resolution = parse_timestamp_arg(o, 'mtime', opt.mtime_resolution) + ctime_resolution = parse_timestamp_arg(o, 'ctime', opt.ctime_resolution) treat_include_fields_as_definitive = True for flag, value in flags: diff --git a/lib/bup/compat.py b/lib/bup/compat.py index c3225a5..7272201 100644 --- a/lib/bup/compat.py +++ b/lib/bup/compat.py @@ -16,6 +16,8 @@ if py3: from os import environb as environ from os import fsdecode, fsencode from shlex import quote + # pylint: disable=undefined-variable + # (for python2 looking here) ModuleNotFoundError = ModuleNotFoundError input = input range = range @@ -93,9 +95,14 @@ else: # Python 2 # pylint: disable=unused-import from bup.py2raise import reraise + # on py3 this causes errors, obviously + # pylint: disable=undefined-variable input = raw_input + # pylint: disable=undefined-variable range = xrange + # pylint: disable=undefined-variable str_type = basestring + # pylint: disable=undefined-variable int_types = (int, long) hexstr = hexlify -- 2.39.2