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

loader: drop compatibility code for old-style Phenny/Jenni modules #2126

Merged
merged 1 commit into from
Jul 7, 2021
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
17 changes: 1 addition & 16 deletions sopel/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,22 +101,7 @@ def clean_callable(func, config):
if not hasattr(func, 'event'):
func.event = ['PRIVMSG']
else:
if isinstance(func.event, (str, bytes)):
func.event = [func.event.upper()]
else:
func.event = [event.upper() for event in func.event]

# TODO: remove in Sopel 8
# Stay compatible with old Phenny/Jenni "modules" (plugins)
# that set the attribute directly
if hasattr(func, 'rule') and isinstance(func.rule, (str, bytes)):
LOGGER.warning(
'The `rule` attribute of %s.%s should be a list, not a string; '
'this behavior is deprecated in Sopel 7.1 '
'and will be removed in Sopel 8. '
'To prevent this problem always use `sopel.plugin.rule(%r)`.',
func.__module__, func.__name__, func.rule)
func.rule = [func.rule]
func.event = [event.upper() for event in func.event]

if any(hasattr(func, attr) for attr in ['commands', 'nickname_commands', 'action_commands']):
if hasattr(func, 'example'):
Expand Down
42 changes: 0 additions & 42 deletions test/test_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,18 +373,6 @@ def test_clean_callable_event(tmpconfig, func):
assert func.global_rate == 0


def test_clean_callable_event_string(tmpconfig, func):
setattr(func, 'event', 'some')
loader.clean_callable(func, tmpconfig)

assert hasattr(func, 'event')
assert func.event == ['SOME']

# idempotency
loader.clean_callable(func, tmpconfig)
assert func.event == ['SOME']


def test_clean_callable_rule(tmpconfig, func):
setattr(func, 'rule', [r'abc'])
loader.clean_callable(func, tmpconfig)
Expand Down Expand Up @@ -426,22 +414,6 @@ def test_clean_callable_rule(tmpconfig, func):
assert func.global_rate == 0


def test_clean_callable_rule_string(tmpconfig, func):
setattr(func, 'rule', r'abc')
loader.clean_callable(func, tmpconfig)

assert hasattr(func, 'rule')
assert len(func.rule) == 1

# Test the regex is compiled properly
assert func.rule[0] == r'abc'

# idempotency
loader.clean_callable(func, tmpconfig)
assert len(func.rule) == 1
assert func.rule[0] == r'abc'


def test_clean_callable_rule_nick(tmpconfig, func):
"""Assert ``$nick`` in a rule is not replaced (deprecated feature)."""
setattr(func, 'rule', [r'$nickhello'])
Expand Down Expand Up @@ -634,20 +606,6 @@ def test_clean_callable_events(tmpconfig, func):
assert func.event == ['TOPIC', 'JOIN', 'NICK']


def test_clean_callable_events_basestring(tmpconfig, func):
setattr(func, 'event', 'topic')
loader.clean_callable(func, tmpconfig)

assert hasattr(func, 'event')
assert func.event == ['TOPIC']

setattr(func, 'event', 'JOIN')
loader.clean_callable(func, tmpconfig)

assert hasattr(func, 'event')
assert func.event == ['JOIN']


def test_clean_callable_example(tmpconfig, func):
module.commands('test')(func)
module.example('.test hello')(func)
Expand Down