Fix redefined-outer-name pylint errors

This commit is contained in:
Philipp Hörist 2018-09-16 17:11:52 +02:00 committed by Philipp Hörist
parent e952739dee
commit eb6f5761ec
16 changed files with 68 additions and 73 deletions

View File

@ -711,12 +711,12 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
""" """
pass pass
def _on_drag_leave(self, widget, context, time): def _on_drag_leave(self, *args):
# FIXME: DND on non editable TextView, find a better way # FIXME: DND on non editable TextView, find a better way
self.drag_entered = False self.drag_entered = False
self.conv_textview.tv.set_editable(False) self.conv_textview.tv.set_editable(False)
def _on_drag_motion(self, widget, context, x, y, time): def _on_drag_motion(self, *args):
# FIXME: DND on non editable TextView, find a better way # FIXME: DND on non editable TextView, find a better way
if not self.drag_entered: if not self.drag_entered:
# We drag new data over the TextView, make it editable to catch dnd # We drag new data over the TextView, make it editable to catch dnd

View File

@ -96,17 +96,17 @@ class CommandProcessor:
return True return True
def execute_command(self, name, arguments): def execute_command(self, name, arguments):
command = self.get_command(name) cmd = self.get_command(name)
args, opts = parse_arguments(arguments) if arguments else ([], []) args, opts = parse_arguments(arguments) if arguments else ([], [])
args, kwargs = adapt_arguments(command, arguments, args, opts) args, kwargs = adapt_arguments(cmd, arguments, args, opts)
if self.command_preprocessor(command, name, arguments, args, kwargs): if self.command_preprocessor(cmd, name, arguments, args, kwargs):
return return
value = command(self, *args, **kwargs) value = cmd(self, *args, **kwargs)
self.command_postprocessor(command, name, arguments, args, kwargs, value) self.command_postprocessor(cmd, name, arguments, args, kwargs, value)
def command_preprocessor(self, command, name, arguments, args, kwargs): def command_preprocessor(self, cmd, name, arguments, args, kwargs):
""" """
Redefine this method in the subclass to execute custom code Redefine this method in the subclass to execute custom code
before command gets executed. before command gets executed.
@ -116,7 +116,7 @@ class CommandProcessor:
""" """
pass pass
def command_postprocessor(self, command, name, arguments, args, kwargs, value): def command_postprocessor(self, cmd, name, arguments, args, kwargs, value):
""" """
Redefine this method in the subclass to execute custom code Redefine this method in the subclass to execute custom code
after command gets executed. after command gets executed.
@ -135,10 +135,10 @@ class CommandProcessor:
pass pass
def get_command(self, name): def get_command(self, name):
command = get_command(self.COMMAND_HOST, name) cmd = get_command(self.COMMAND_HOST, name)
if not command: if not cmd:
raise NoCommandError("Command does not exist", name=name) raise NoCommandError("Command does not exist", name=name)
return command return cmd
def list_commands(self): def list_commands(self):
commands = list_commands(self.COMMAND_HOST) commands = list_commands(self.COMMAND_HOST)
@ -307,16 +307,16 @@ def command(*names, **properties):
Decorator which receives handler as a first argument and then Decorator which receives handler as a first argument and then
wraps it in the command which then returns back. wraps it in the command which then returns back.
""" """
command = Command(handler, *names, **properties) cmd = Command(handler, *names, **properties)
# Extract and inject a native name if either no other names are # Extract and inject a native name if either no other names are
# specified or native property is enabled, while making # specified or native property is enabled, while making
# sure it is going to be the first one in the list. # sure it is going to be the first one in the list.
if not names or native: if not names or native:
names.insert(0, command.native_name) names.insert(0, cmd.native_name)
command.names = tuple(names) cmd.names = tuple(names)
return command return cmd
# Workaround if we are getting called without parameters. Keep in # Workaround if we are getting called without parameters. Keep in
# mind that in that case - first item in the names will be the # mind that in that case - first item in the names will be the

View File

@ -43,25 +43,25 @@ class StandardCommonCommands(CommandContainer):
@command(overlap=True) @command(overlap=True)
@doc(_("Show help on a given command or a list of available commands if -a is given")) @doc(_("Show help on a given command or a list of available commands if -a is given"))
def help(self, command=None, all=False): def help(self, cmd=None, all=False):
if command: if cmd:
command = self.get_command(command) cmd = self.get_command(cmd)
documentation = _(command.extract_documentation()) documentation = _(cmd.extract_documentation())
usage = generate_usage(command) usage = generate_usage(cmd)
text = [] text = []
if documentation: if documentation:
text.append(documentation) text.append(documentation)
if command.usage: if cmd.usage:
text.append(usage) text.append(usage)
return '\n\n'.join(text) return '\n\n'.join(text)
elif all: elif all:
for command in self.list_commands(): for cmd in self.list_commands():
names = ', '.join(command.names) names = ', '.join(cmd.names)
description = command.extract_description() description = cmd.extract_description()
self.echo("%s - %s" % (names, description)) self.echo("%s - %s" % (names, description))
else: else:

View File

@ -42,8 +42,8 @@ except ImportError:
else: else:
try: try:
# test if dbus-x11 is installed # test if dbus-x11 is installed
bus = dbus.SystemBus() _bus = dbus.SystemBus()
bus = dbus.SessionBus() _bus = dbus.SessionBus()
supported = True # does user have D-Bus bindings? supported = True # does user have D-Bus bindings?
except dbus.DBusException: except dbus.DBusException:
supported = False supported = False

View File

@ -61,16 +61,15 @@ class Event:
class ChatEvent(Event): class ChatEvent(Event):
type_ = 'chat' type_ = 'chat'
def __init__ (self, message, subject, kind, time, encrypted, resource, def __init__ (self, message, subject, kind, time_, encrypted, resource,
msg_log_id, correct_id=None, xhtml=None, session=None, form_node=None, msg_log_id, correct_id=None, xhtml=None, session=None, form_node=None,
displaymarking=None, sent_forwarded=False, time_=None, show_in_roster=False, displaymarking=None, sent_forwarded=False, show_in_roster=False,
show_in_systray=True, additional_data=None): show_in_systray=True, additional_data=None):
Event.__init__(self, time_, show_in_roster=show_in_roster, Event.__init__(self, time_, show_in_roster=show_in_roster,
show_in_systray=show_in_systray) show_in_systray=show_in_systray)
self.message = message self.message = message
self.subject = subject self.subject = subject
self.kind = kind self.kind = kind
self.time = time
self.encrypted = encrypted self.encrypted = encrypted
self.resource = resource self.resource = resource
self.msg_log_id = msg_log_id self.msg_log_id = msg_log_id

View File

@ -1279,7 +1279,6 @@ def get_subscription_request_msg(account=None):
return s return s
def replace_dataform_media(form, stanza): def replace_dataform_media(form, stanza):
import nbxmpp
found = False found = False
for field in form.getTags('field'): for field in form.getTags('field'):
for media in field.getTags('media'): for media in field.getTags('media'):

View File

@ -354,7 +354,7 @@ class Zeroconf:
# connect to dbus # connect to dbus
def connect_dbus(self): def connect_dbus(self):
try: try:
import dbus import dbus # pylint: disable=redefined-outer-name
from dbus.mainloop.glib import DBusGMainLoop from dbus.mainloop.glib import DBusGMainLoop
main_loop = DBusGMainLoop(set_as_default=True) main_loop = DBusGMainLoop(set_as_default=True)
dbus.set_default_main_loop(main_loop) dbus.set_default_main_loop(main_loop)

View File

@ -2094,11 +2094,11 @@ class DiscussionGroupsBrowser(AgentBrowser):
except Exception: except Exception:
return return
groups = set() groups_ = set()
for child in subscriptions.getTags('subscription'): for child in subscriptions.getTags('subscription'):
groups.add(child['node']) groups_.add(child['node'])
self.subscriptions = groups self.subscriptions = groups_
# try to setup existing items in model # try to setup existing items in model
model = self.window.services_treeview.get_model() model = self.window.services_treeview.get_model()
@ -2108,7 +2108,7 @@ class DiscussionGroupsBrowser(AgentBrowser):
# 4 = subscribed? # 4 = subscribed?
groupnode = row[1] groupnode = row[1]
row[3] = False row[3] = False
row[4] = groupnode in groups row[4] = groupnode in groups_
# we now know subscriptions, update button states # we now know subscriptions, update button states
self.update_actions() self.update_actions()

View File

@ -38,7 +38,6 @@ def _check_required_deps():
print('Gajim needs python-nbxmpp to run. Quitting…') print('Gajim needs python-nbxmpp to run. Quitting…')
sys.exit(1) sys.exit(1)
from distutils.version import LooseVersion as V
if V(nbxmpp.__version__) < V(_MIN_NBXMPP_VER): if V(nbxmpp.__version__) < V(_MIN_NBXMPP_VER):
print('Gajim needs python-nbxmpp >= %s to run. ' print('Gajim needs python-nbxmpp >= %s to run. '
'Quitting...' % _MIN_NBXMPP_VER) 'Quitting...' % _MIN_NBXMPP_VER)

View File

@ -24,11 +24,12 @@ from gajim.common import configpaths
from gajim.common import helpers from gajim.common import helpers
from gajim.common import connection from gajim.common import connection
from gajim.common.modules import dataforms from gajim.common.modules import dataforms
from gajim.config import ManageProxiesWindow
from gajim.config import FakeDataForm
from gajim.gtk.util import get_builder from gajim.gtk.util import get_builder
from gajim.gtk import ErrorDialog from gajim.gtk import ErrorDialog
from gajim import gtkgui_helpers from gajim import gtkgui_helpers
from gajim import dataforms_widget from gajim import dataforms_widget
from gajim import config
from gajim import gui_menu_builder from gajim import gui_menu_builder
@ -347,7 +348,7 @@ class AccountCreationWizard:
app.interface.instances['manage_proxies'].window.present() app.interface.instances['manage_proxies'].window.present()
else: else:
app.interface.instances['manage_proxies'] = \ app.interface.instances['manage_proxies'] = \
config.ManageProxiesWindow() ManageProxiesWindow()
def on_custom_host_port_checkbutton_toggled(self, widget): def on_custom_host_port_checkbutton_toggled(self, widget):
self.xml.get_object('custom_host_hbox').set_sensitive( self.xml.get_object('custom_host_hbox').set_sensitive(
@ -377,8 +378,7 @@ class AccountCreationWizard:
self.data_form_widget.set_data_form(dataform) self.data_form_widget.set_data_form(dataform)
empty_config = False empty_config = False
else: else:
self.data_form_widget = config.FakeDataForm( self.data_form_widget = FakeDataForm(obj.config, selectable=True)
obj.config, selectable=True)
for field in obj.config: for field in obj.config:
if field in ('key', 'instructions', 'x', 'registered'): if field in ('key', 'instructions', 'x', 'registered'):
continue continue

View File

@ -198,8 +198,7 @@ def at_the_end(widget):
""" """
adj_v = widget.get_vadjustment() adj_v = widget.get_vadjustment()
max_scroll_pos = adj_v.get_upper() - adj_v.get_page_size() max_scroll_pos = adj_v.get_upper() - adj_v.get_page_size()
at_the_end = (adj_v.get_value() == max_scroll_pos) return adj_v.get_value() == max_scroll_pos
return at_the_end
def get_image_button(icon_name, tooltip, toggle=False): def get_image_button(icon_name, tooltip, toggle=False):

View File

@ -211,8 +211,7 @@ def at_the_end(widget):
""" """
adj_v = widget.get_vadjustment() adj_v = widget.get_vadjustment()
max_scroll_pos = adj_v.get_upper() - adj_v.get_page_size() max_scroll_pos = adj_v.get_upper() - adj_v.get_page_size()
at_the_end = (adj_v.get_value() == max_scroll_pos) return adj_v.get_value() == max_scroll_pos
return at_the_end
def scroll_to_end(widget): def scroll_to_end(widget):
"""Scrolls to the end of a GtkScrolledWindow. """Scrolls to the end of a GtkScrolledWindow.

View File

@ -72,7 +72,7 @@ classes = {
} }
# styles for elements # styles for elements
element_styles = { _element_styles = {
'u' : ';text-decoration: underline', 'u' : ';text-decoration: underline',
'em' : ';font-style: oblique', 'em' : ';font-style: oblique',
'cite' : '; background-color:rgb(170,190,250);' 'cite' : '; background-color:rgb(170,190,250);'
@ -90,12 +90,12 @@ element_styles = {
'dd' : ';margin-left: 2em; font-style: oblique' 'dd' : ';margin-left: 2em; font-style: oblique'
} }
# no difference for the moment # no difference for the moment
element_styles['dfn'] = element_styles['em'] _element_styles['dfn'] = _element_styles['em']
element_styles['var'] = element_styles['em'] _element_styles['var'] = _element_styles['em']
# deprecated, legacy, presentational # deprecated, legacy, presentational
element_styles['tt'] = element_styles['kbd'] _element_styles['tt'] = _element_styles['kbd']
element_styles['i'] = element_styles['em'] _element_styles['i'] = _element_styles['em']
element_styles['b'] = element_styles['strong'] _element_styles['b'] = _element_styles['strong']
# ========== # ==========
# XEP-0071 # XEP-0071
@ -182,12 +182,12 @@ INLINE = INLINE_PHRASAL.union(INLINE_PRES).union(INLINE_STRUCT)
LIST_ELEMS = set( 'dl, ol, ul'.split(', ')) LIST_ELEMS = set( 'dl, ol, ul'.split(', '))
for name in BLOCK_HEAD: for _name in BLOCK_HEAD:
num = eval(name[1]) _num = eval(_name[1])
header_size = (num-1) // 2 _header_size = (_num - 1) // 2
weight = (num - 1) % 2 _weight = (_num - 1) % 2
element_styles[name] = '; font-size: %s; %s' % ( ('large', 'medium', 'small')[header_size], _element_styles[_name] = '; font-size: %s; %s' % ( ('large', 'medium', 'small')[_header_size],
('font-weight: bold', 'font-style: oblique')[weight],) ('font-weight: bold', 'font-style: oblique')[_weight],)
def _parse_css_color(color): def _parse_css_color(color):
if color.startswith('rgb(') and color.endswith(')'): if color.startswith('rgb(') and color.endswith(')'):
@ -741,8 +741,8 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
style += ';margin-left: 2em' style += ';margin-left: 2em'
elif name == 'img': elif name == 'img':
tag = self._process_img(attrs) tag = self._process_img(attrs)
if name in element_styles: if name in _element_styles:
style += element_styles[name] style += _element_styles[name]
# so that explicit styles override implicit ones, # so that explicit styles override implicit ones,
# we add the attribute last # we add the attribute last
style += ";"+attrs.get('style', '') style += ";"+attrs.get('style', '')
@ -915,8 +915,8 @@ class HtmlTextView(Gtk.TextView):
AddNewContactWindow(self.account, jid) AddNewContactWindow(self.account, jid)
def make_link_menu(self, event, kind, text): def make_link_menu(self, event, kind, text):
xml = get_builder('chat_context_menu.ui') ui = get_builder('chat_context_menu.ui')
menu = xml.get_object('chat_context_menu') menu = ui.get_object('chat_context_menu')
childs = menu.get_children() childs = menu.get_children()
if kind == 'url': if kind == 'url':
childs[0].connect('activate', self.on_copy_link_activate, text) childs[0].connect('activate', self.on_copy_link_activate, text)
@ -930,7 +930,7 @@ class HtmlTextView(Gtk.TextView):
childs[7].hide() # add to roster childs[7].hide() # add to roster
else: # It's a mail or a JID else: # It's a mail or a JID
# load muc icon # load muc icon
join_group_chat_menuitem = xml.get_object('join_group_chat_menuitem') join_group_chat_menuitem = ui.get_object('join_group_chat_menuitem')
text = text.lower() text = text.lower()
if text.startswith('xmpp:'): if text.startswith('xmpp:'):
@ -1270,9 +1270,9 @@ hhx4dbgYKAAA7' alt='Larry'/>
frame.set_shadow_type(Gtk.ShadowType.IN) frame.set_shadow_type(Gtk.ShadowType.IN)
frame.show() frame.show()
frame.add(sw) frame.add(sw)
w = Gtk.Window() win = Gtk.Window()
w.add(frame) win.add(frame)
w.set_default_size(400, 300) win.set_default_size(400, 300)
w.show_all() win.show_all()
w.connect('destroy', lambda w: Gtk.main_quit()) win.connect('destroy', lambda win: Gtk.main_quit())
Gtk.main() Gtk.main()

View File

@ -199,7 +199,7 @@ class MusicTrackListener(GObject.GObject):
# here we test :) # here we test :)
if __name__ == '__main__': if __name__ == '__main__':
def music_track_change_cb(listener, music_track_info): def music_track_change_cb(_listener, music_track_info):
if music_track_info is None or music_track_info.paused: if music_track_info is None or music_track_info.paused:
print('Stop!') print('Stop!')
else: else:

View File

@ -51,7 +51,7 @@ class log_calls:
even though `log_calls` decorator is used. even though `log_calls` decorator is used.
''' '''
def __init__(self, classname='', log=log): def __init__(self, classname=''):
''' '''
:Keywords: :Keywords:
classname : str classname : str

View File

@ -278,7 +278,7 @@ class VcardWindow:
return return
i = 0 i = 0
client = '' client = ''
os = '' os_info = ''
while i in self.os_info: while i in self.os_info:
if self.os_info[i]['resource'] == obj.jid.getResource(): if self.os_info[i]['resource'] == obj.jid.getResource():
if obj.client_info: if obj.client_info:
@ -296,13 +296,13 @@ class VcardWindow:
self.os_info[i]['os'] = Q_('?OS:Unknown') self.os_info[i]['os'] = Q_('?OS:Unknown')
if i > 0: if i > 0:
client += '\n' client += '\n'
os += '\n' os_info += '\n'
client += self.os_info[i]['client'] client += self.os_info[i]['client']
os += self.os_info[i]['os'] os_info += self.os_info[i]['os']
i += 1 i += 1
self.xml.get_object('client_name_version_label').set_text(client) self.xml.get_object('client_name_version_label').set_text(client)
self.xml.get_object('os_label').set_text(os) self.xml.get_object('os_label').set_text(os_info)
self.os_info_arrived = True self.os_info_arrived = True
def set_entity_time(self, obj): def set_entity_time(self, obj):