From 46f3ffadf3de6237858574f2ba9d1cebb1a53368 Mon Sep 17 00:00:00 2001 From: dgw Date: Mon, 28 Jun 2021 00:58:12 -0500 Subject: [PATCH] loader: drop compatibility code for old-style Phenny/Jenni modules Way back, before the `plugin` (or `module`) decorators were a thing, "modules" of the time were written by directly assigning attributes of each callable to add the required properties for the bot's loader. We don't support that any more. Code like that is probably five or more years old *at minimum*, and should be updated. Also drops related tests, of course. --- sopel/loader.py | 17 +---------------- test/test_loader.py | 42 ------------------------------------------ 2 files changed, 1 insertion(+), 58 deletions(-) diff --git a/sopel/loader.py b/sopel/loader.py index 93a57372b0..de390ba30e 100644 --- a/sopel/loader.py +++ b/sopel/loader.py @@ -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'): diff --git a/test/test_loader.py b/test/test_loader.py index 03d8a1ddc9..94387d1484 100644 --- a/test/test_loader.py +++ b/test/test_loader.py @@ -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) @@ -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']) @@ -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)