Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unignore more style checks #1561

Merged
merged 6 commits into from
Apr 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ coveralls
flake8<3.6.0; python_version == '3.3'
flake8>=3.6.0,<3.7.0; python_version != '3.3'
flake8-coding
flake8-future-import
dgw marked this conversation as resolved.
Show resolved Hide resolved
setuptools<40.0; python_version == '3.3'
25 changes: 14 additions & 11 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@ ignore =
E501,E128,E127,
# These are ignored by default (and we want to keep them ignored)
W504,
# These are forbidding certain __future__ imports. The plugin has errors both
# for having and not having them; we want to always have them, so we ignore
# the having them errors and keep the not having them errors.
FI50,FI51,FI52,FI53,FI54,FI55,
# F12 is with_statement, which is already in 2.7. F15 requires and F55 forbids
# generator_stop, which should probably be made mandatory at some point.
F12,F15,F55,
# These are rules that are relatively new or have had their definitions tweaked
# recently, so we'll forgive them until versions of PEP8 in various developers'
# distros are updated
E265,E713,E111,E113,E402,E731
# These are forbidding certain __future__ imports. The future-import plugin
# has errors both for having and not having them; we want to have these until
# Sopel no longer supports Python versions that require them.
FI50,FI51,FI53,FI54,FI55,
# These would require future imports that are not needed any more on Sopel's
# oldest supported Python version (2.7).
FI12,FI16,FI17,
# We ignore the error for missing generator_stop because it's only available
# in Python 3.5+ (switch this to FI55 in the above list when Sopel drops
# support for Python older than 3.5)
FI15
# flake8-future-import doesn't support (as of last update) the "annotations"
# feature added in Python 3.7, but it should be ignored too when/if this is
# ever released: https://github.com/xZise/flake8-future-import/pull/19
exclude =
docs/*,
env/*,
Expand Down
7 changes: 3 additions & 4 deletions sopel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@

from __future__ import unicode_literals, absolute_import, print_function, division

from collections import namedtuple
import locale
import re
import sys

loc = locale.getlocale()
if sys.version_info.major > 2:
if not loc[1] or 'UTF-8' not in loc[1]:
Expand All @@ -22,10 +25,6 @@
'stupid things. If you get strange errors, please set it to '
'something like "en_US.UTF-8".', file=sys.stderr)


from collections import namedtuple
import re

__version__ = '6.6.6'


Expand Down
3 changes: 0 additions & 3 deletions sopel/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,6 @@ def call(self, func, sopel, trigger):
if func in self._times[nick]:
usertimediff = current_time - self._times[nick][func]
if func.rate > 0 and usertimediff < func.rate:
#self._times[nick][func] = current_time
LOGGER.info(
"%s prevented from using %s in %s due to user limit: %d < %d",
trigger.nick, func.__name__, trigger.sender, usertimediff,
Expand All @@ -412,7 +411,6 @@ def call(self, func, sopel, trigger):
if func in self._times[self.nick]:
globaltimediff = current_time - self._times[self.nick][func]
if func.global_rate > 0 and globaltimediff < func.global_rate:
#self._times[self.nick][func] = current_time
LOGGER.info(
"%s prevented from using %s in %s due to global limit: %d < %d",
trigger.nick, func.__name__, trigger.sender, globaltimediff,
Expand All @@ -423,7 +421,6 @@ def call(self, func, sopel, trigger):
if not trigger.is_privmsg and func in self._times[trigger.sender]:
chantimediff = current_time - self._times[trigger.sender][func]
if func.channel_rate > 0 and chantimediff < func.channel_rate:
#self._times[trigger.sender][func] = current_time
LOGGER.info(
"%s prevented from using %s in %s due to channel limit: %d < %d",
trigger.nick, func.__name__, trigger.sender, chantimediff,
Expand Down
26 changes: 11 additions & 15 deletions sopel/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,15 @@
"""
from __future__ import unicode_literals, absolute_import, print_function, division

import sys

from sopel import tools

if sys.version_info < (2, 7):
tools.stderr('Error: Requires Python 2.7 or later. Try python2.7 sopel')
sys.exit(1)
if sys.version_info.major == 2:
tools.stderr('Warning: Python 2.x is near end of life. Sopel support at that point is TBD.')
if sys.version_info.major == 3 and sys.version_info.minor < 3:
tools.stderr('Error: When running on Python 3, Python 3.3 is required.')
sys.exit(1)

import argparse
import os
import platform
import signal
import sys
import time
import traceback

from sopel import bot, logger, __version__
from sopel import bot, logger, tools, __version__
from sopel.config import (
Config,
_create_config,
Expand All @@ -41,6 +29,14 @@
)
from . import utils

if sys.version_info < (2, 7):
tools.stderr('Error: Requires Python 2.7 or later. Try python2.7 sopel')
sys.exit(1)
if sys.version_info.major == 2:
tools.stderr('Warning: Python 2.x is near end of life. Sopel support at that point is TBD.')
if sys.version_info.major == 3 and sys.version_info.minor < 3:
tools.stderr('Error: When running on Python 3, Python 3.3 is required.')
sys.exit(1)

ERR_CODE = 1
"""Error code: program exited with an error"""
Expand Down Expand Up @@ -635,7 +631,7 @@ def main(argv=None):
parser = build_parser()

# make sure to have an action first (`legacy` by default)
# TODO: `start` should be the default in Sopel 8
# TODO: `start` should be the default in Sopel 8
dgw marked this conversation as resolved.
Show resolved Hide resolved
argv = argv or sys.argv[1:]
if not argv:
argv = ['legacy']
Expand Down
13 changes: 7 additions & 6 deletions sopel/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,20 @@

from __future__ import unicode_literals, absolute_import, print_function, division

from sopel.tools import iteritems, stderr
import sopel.tools
from sopel.tools import get_input
import sopel.loader
import os
import sys

import sopel.config.core_section
from sopel.config.types import StaticSection
import sopel.loader
import sopel.tools
from sopel.tools import get_input, iteritems, stderr

if sys.version_info.major < 3:
import ConfigParser
else:
basestring = str
import configparser as ConfigParser
import sopel.config.core_section
from sopel.config.types import StaticSection


DEFAULT_HOMEDIR = os.path.join(os.path.expanduser('~'), '.sopel')
Expand Down
4 changes: 3 additions & 1 deletion sopel/modules/calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@

if sys.version_info.major < 3:
from urllib import quote as _quote
quote = lambda s: _quote(s.encode('utf-8')).decode('utf-8')

def quote(s):
return _quote(s.encode('utf-8')).decode('utf-8')
else:
from urllib.parse import quote

Expand Down
4 changes: 3 additions & 1 deletion sopel/modules/dice.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ def roll(bot, trigger):
arg_str = arg_str.replace("%", "%%")
arg_str = re.sub(dice_regexp, "%s", arg_str)

f = lambda dice_expr: _roll_dice(bot, dice_expr)
def f(dice_expr):
return _roll_dice(bot, dice_expr)

dice = list(map(f, dice_expressions))

if None in dice:
Expand Down
2 changes: 1 addition & 1 deletion sopel/modules/emoticons.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

https://sopel.chat
"""
from __future__ import unicode_literals, absolute_import
from __future__ import unicode_literals, absolute_import, print_function, division
from sopel.module import commands, example


Expand Down
7 changes: 5 additions & 2 deletions sopel/modules/find.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,12 @@ def findandreplace(bot, trigger):
# off case sensitivity. re.U turns on unicode replacement.
if 'i' in flags:
regex = re.compile(re.escape(rest[0]), re.U | re.I)
repl = lambda s: re.sub(regex, rest[1], s, count == 1)

def repl(s):
return re.sub(regex, rest[1], s, count == 1)
else:
repl = lambda s: s.replace(rest[0], rest[1], count)
def repl(s):
return s.replace(rest[0], rest[1], count)

# Look back through the user's lines in the channel until you find a line
# where the replacement works
Expand Down
4 changes: 3 additions & 1 deletion sopel/modules/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ def help(bot, trigger):
if len(bot.doc[name][0]) + (1 if bot.doc[name][1] else 0) > threshold:
if trigger.nick != trigger.sender: # don't say that if asked in private
bot.reply('The documentation for this command is too long; I\'m sending it to you in a private message.')
msgfun = lambda l: bot.msg(trigger.nick, l)

def msgfun(l):
bot.msg(trigger.nick, l)
else:
msgfun = bot.reply

Expand Down
2 changes: 1 addition & 1 deletion sopel/modules/isup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def isup(bot, trigger):
else:
site = 'http://' + site

if not '.' in site:
if '.' not in site:
site += ".com"

try:
Expand Down
14 changes: 8 additions & 6 deletions sopel/modules/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@
import re
import sys

if sys.version_info.major < 3:
from urllib import unquote as _unquote
unquote = lambda s: _unquote(s.encode('utf-8')).decode('utf-8')
else:
from urllib.parse import unquote

import requests
import xmltodict

from sopel import web
from sopel.module import commands, example

if sys.version_info.major < 3:
from urllib import unquote as _unquote

def unquote(s):
return _unquote(s.encode('utf-8')).decode('utf-8')
else:
from urllib.parse import unquote


def formatnumber(n):
"""Format a number with beautiful commas."""
Expand Down
4 changes: 2 additions & 2 deletions sopel/modules/tell.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ def f_remind(bot, trigger):
if tellee == bot.nick:
return bot.reply("I'm here now, you can tell me whatever you want!")

if not tellee in (Identifier(teller), bot.nick, 'me'):
if tellee not in (Identifier(teller), bot.nick, 'me'):
tz = get_timezone(bot.db, bot.config, None, tellee)
timenow = format_time(bot.db, bot.config, tz, tellee)
bot.memory['tell_lock'].acquire()
try:
if not tellee in bot.memory['reminders']:
if tellee not in bot.memory['reminders']:
bot.memory['reminders'][tellee] = [(teller, verb, timenow, msg)]
else:
bot.memory['reminders'][tellee].append((teller, verb, timenow, msg))
Expand Down
8 changes: 6 additions & 2 deletions sopel/modules/wikipedia.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@
if sys.version_info.major < 3:
from urllib import quote as _quote
from urlparse import unquote as _unquote
quote = lambda s: _quote(s.encode('utf-8')).decode('utf-8')
unquote = lambda s: _unquote(s.encode('utf-8')).decode('utf-8')

def quote(s):
return _quote(s.encode('utf-8')).decode('utf-8')

def unquote(s):
return _unquote(s.encode('utf-8')).decode('utf-8')
else:
from urllib.parse import quote, unquote

Expand Down
2 changes: 0 additions & 2 deletions sopel/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
class MockConfig(sopel.config.Config):
def __init__(self):
self.filename = tempfile.mkstemp()[1]
#self._homedir = tempfile.mkdtemp()
#self.filename = os.path.join(self._homedir, 'test.cfg')
self.parser = ConfigParser.RawConfigParser(allow_no_value=True)
self.parser.add_section('core')
self.parser.set('core', 'owner', 'Embolalia')
Expand Down
4 changes: 3 additions & 1 deletion test/test_loader.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# coding=utf-8
"""Test for the ``sopel.loader`` module."""
"""Tests for the ``sopel.loader`` module."""
from __future__ import unicode_literals, absolute_import, print_function, division

import imp
import inspect
import os
Expand Down