Fixes based on pylint complaints, drop some py2 compat code

This commit is contained in:
Andreas Kloeckner 2021-03-24 17:47:03 -05:00
parent 2711803fe1
commit c4bab4d6bc
8 changed files with 39 additions and 81 deletions

View File

@ -57,12 +57,8 @@ class PudbShortcuts(object):
dbg.set_trace(sys._getframe().f_back, paused=False)
if PY3:
import builtins
builtins.__dict__["pu"] = PudbShortcuts()
else:
import __builtin__
__builtin__.__dict__["pu"] = PudbShortcuts()
import builtins
builtins.__dict__["pu"] = PudbShortcuts()
CURRENT_DEBUGGER = []

View File

@ -7,7 +7,7 @@ from pudb import _get_debugger, set_interrupt_handler
def __myimport__(name, *args, **kwargs): # noqa: N807
if name == "pudb.b":
set_trace()
return __origimport__(name, *args, **kwargs) # noqa: F821
return __origimport__(name, *args, **kwargs) # noqa: F821, E501 # pylint: disable=undefined-variable
# Will only be run on first import

View File

@ -195,10 +195,7 @@ class Debugger(bdb.Bdb):
if steal_output:
raise NotImplementedError("output stealing")
if PY3:
from io import StringIO
else:
from cStringIO import StringIO
from io import StringIO
self.stolen_output = sys.stderr = sys.stdout = StringIO()
sys.stdin = StringIO("") # avoid spurious hangs
@ -1593,11 +1590,8 @@ class DebuggerUI(FrameVarInfoKeeper):
if widget is not new_mod_entry:
mod_name = widget.base_widget.get_text()[0]
mod = sys.modules[mod_name]
if PY3:
import importlib
importlib.reload(mod)
else:
reload(mod) # noqa (undef on Py3)
import importlib
importlib.reload(mod)
self.message("'%s' was successfully reloaded." % mod_name)
@ -1743,10 +1737,7 @@ class DebuggerUI(FrameVarInfoKeeper):
prev_sys_stdout = sys.stdout
prev_sys_stderr = sys.stderr
if PY3:
from io import StringIO
else:
from cStringIO import StringIO
from io import StringIO
sys.stdin = None
sys.stderr = sys.stdout = StringIO()
@ -2041,7 +2032,7 @@ class DebuggerUI(FrameVarInfoKeeper):
def __init__(self, idx):
self.idx = idx
def __call__(subself, w, size, key): # noqa
def __call__(subself, w, size, key): # noqa # pylint: disable=no-self-argument
self.columns.set_focus(self.rhs_col_sigwrap)
self.rhs_col.set_focus(self.rhs_col.widget_list[subself.idx])
@ -2202,10 +2193,10 @@ class DebuggerUI(FrameVarInfoKeeper):
title=None, bind_enter_esc=True, focus_buttons=False,
extra_bindings=[]):
class ResultSetter:
def __init__(subself, res): # noqa
def __init__(subself, res): # noqa # pylint: disable=no-self-argument
subself.res = res
def __call__(subself, btn): # noqa
def __call__(subself, btn): # noqa # pylint: disable=no-self-argument
self.quit_event_loop = [subself.res]
Attr = urwid.AttrMap # noqa
@ -2248,13 +2239,6 @@ class DebuggerUI(FrameVarInfoKeeper):
("fixed", 1, urwid.SolidFill()),
w])
class ResultSetter:
def __init__(subself, res): # noqa
subself.res = res
def __call__(subself, w, size, key): # noqa
self.quit_event_loop = [subself.res]
w = SignalWrap(w)
for key, binding in extra_bindings:
if isinstance(binding, str):

View File

@ -2,27 +2,17 @@ from __future__ import absolute_import, division, print_function
import sys
PY3 = sys.version_info[0] >= 3
if PY3:
raw_input = input
xrange = range
integer_types = (int,)
string_types = (str,)
text_type = str
def execfile(fname, globs, locs=None):
exec(compile(open(fname).read(), fname, "exec"), globs, locs or globs)
raw_input = input
xrange = range
integer_types = (int,)
string_types = (str,)
text_type = str
else:
raw_input = raw_input
xrange = xrange
integer_types = (int, long) # noqa: F821
string_types = (basestring,) # noqa: F821
text_type = unicode # noqa: F821
execfile = execfile
try:
import builtins
from configparser import ConfigParser
except ImportError:
import __builtin__ as builtins # noqa: F401
from ConfigParser import ConfigParser # noqa: F401
def execfile(fname, globs, locs=None):
exec(compile(open(fname).read(), fname, "exec"), globs, locs or globs)
import builtins
from configparser import ConfigParser

View File

@ -53,7 +53,10 @@ def get_save_config_path(*resource):
return None
if not resource:
resource = [XDG_CONF_RESOURCE]
resource = os.path.join(*resource)
# no idea what pylint's problem is here
resource = os.path.join(*resource) # pylint: disable=no-value-for-parameter
assert not resource.startswith("/")
path = os.path.join(XDG_CONFIG_HOME, resource)
if not os.path.isdir(path):

View File

@ -238,13 +238,13 @@ def format_source(debugger_ui, lines, breakpoints):
}
class UrwidFormatter(Formatter):
def __init__(subself, **options): # noqa: N805
def __init__(subself, **options): # noqa: N805, E501 # pylint: disable=no-self-argument
Formatter.__init__(subself, **options)
subself.current_line = ""
subself.current_attr = []
subself.lineno = 1
def format(subself, tokensource, outfile): # noqa: N805
def format(subself, tokensource, outfile): # noqa: N805, E501 # pylint: disable=no-self-argument
def add_snippet(ttype, s):
if not s:
return

View File

@ -308,15 +308,6 @@ class SearchBox(urwid.Edit):
urwid.Edit.__init__(self, [("label", "Search: ")], "")
self.controller = controller
def restart_search(self):
from time import time
now = time()
if self.search_start_time > 5:
self.set_edit_text("")
self.search_time = now
def keypress(self, size, key):
result = urwid.Edit.keypress(self, size, key)
txt = self.get_edit_text()

View File

@ -28,6 +28,8 @@ THE SOFTWARE.
"""
from abc import ABC, abstractmethod
# {{{ constants and imports
import urwid
@ -372,22 +374,9 @@ class VariableWidget(urwid.FlowWidget):
# Ellipses to show text was cut off
#encoding = urwid.util.detected_encoding
if False: # encoding[:3] == "UTF":
# Unicode is supported, use single character ellipsis
for i in xrange(len(text)):
if len(text[i]) > maxcol:
text[i] = (unicode(text[i][:maxcol-1]) # noqa: F821
+ ELLIPSIS + unicode(text[i][maxcol:])) # noqa: F821
# XXX: This doesn't work. It just gives a ?
# Strangely, the following does work (it gives the …
# three characters from the right):
#
# text[i] = (unicode(text[i][:maxcol-3])
# + unicode(u'…')) + unicode(text[i][maxcol-2:])
else:
for i in xrange(len(text)):
if text_width(text[i]) > maxcol:
text[i] = text[i][:maxcol-3] + "..."
for i in xrange(len(text)):
if text_width(text[i]) > maxcol:
text[i] = text[i][:maxcol-3] + "..."
return make_canvas(text, attr, maxcol, apfx+"value")
@ -477,7 +466,7 @@ def get_stringifier(iinfo):
# {{{ tree walking
class ValueWalker:
class ValueWalker(ABC):
BASIC_TYPES = []
BASIC_TYPES.append(type(None))
BASIC_TYPES.extend(integer_types)
@ -494,6 +483,10 @@ class ValueWalker:
def __init__(self, frame_var_info):
self.frame_var_info = frame_var_info
@abstractmethod
def add_item(self, parent, var_label, value_str, id_path, attr_prefix=None):
pass
def add_continuation_item(self, parent: VariableWidget, id_path: str,
count: int, length: int) -> bool:
"""
@ -745,7 +738,8 @@ class FrameVarInfoKeeper(object):
def get_frame_var_info(self, read_only, ssid=None):
if ssid is None:
ssid = self.debugger.get_stack_situation_id()
# self.debugger set by subclass
ssid = self.debugger.get_stack_situation_id() # noqa: E501 # pylint: disable=no-member
if read_only:
return self.frame_var_info.get(ssid, FrameVarInfo())
else: