mirror of
https://github.com/nvbn/thefuck.git
synced 2025-01-18 20:11:17 +00:00
#N/A: Remove old-style rules support
This commit is contained in:
parent
c63e0d1582
commit
46cb87615e
@ -6,7 +6,7 @@ from mock import Mock
|
||||
import six
|
||||
from thefuck.utils import default_settings, \
|
||||
memoize, get_closest, get_all_executables, replace_argument, \
|
||||
get_all_matched_commands, is_app, for_app, cache, compatibility_call, \
|
||||
get_all_matched_commands, is_app, for_app, cache, \
|
||||
get_valid_history_without_current
|
||||
from tests.utils import Command
|
||||
|
||||
@ -188,56 +188,6 @@ class TestCache(object):
|
||||
assert shelve == {key: {'etag': '0', 'value': 'test'}}
|
||||
|
||||
|
||||
class TestCompatibilityCall(object):
|
||||
def test_match(self):
|
||||
def match(command):
|
||||
assert command == Command()
|
||||
return True
|
||||
|
||||
assert compatibility_call(match, Command())
|
||||
|
||||
def test_old_match(self, settings):
|
||||
def match(command, _settings):
|
||||
assert command == Command()
|
||||
assert settings == _settings
|
||||
return True
|
||||
|
||||
with pytest.warns(UserWarning):
|
||||
assert compatibility_call(match, Command())
|
||||
|
||||
def test_get_new_command(self):
|
||||
def get_new_command(command):
|
||||
assert command == Command()
|
||||
return True
|
||||
|
||||
assert compatibility_call(get_new_command, Command())
|
||||
|
||||
def test_old_get_new_command(self, settings):
|
||||
def get_new_command(command, _settings):
|
||||
assert command == Command()
|
||||
assert settings == _settings
|
||||
return True
|
||||
|
||||
with pytest.warns(UserWarning):
|
||||
assert compatibility_call(get_new_command, Command())
|
||||
|
||||
def test_side_effect(self):
|
||||
def side_effect(command, new_command):
|
||||
assert command == Command() == new_command
|
||||
return True
|
||||
|
||||
assert compatibility_call(side_effect, Command(), Command())
|
||||
|
||||
def test_old_side_effect(self, settings):
|
||||
def side_effect(command, new_command, _settings):
|
||||
assert command == Command() == new_command
|
||||
assert settings == _settings
|
||||
return True
|
||||
|
||||
with pytest.warns(UserWarning):
|
||||
assert compatibility_call(side_effect, Command(), Command())
|
||||
|
||||
|
||||
class TestGetValidHistoryWithoutCurrent(object):
|
||||
@pytest.yield_fixture(autouse=True)
|
||||
def fail_on_warning(self):
|
||||
|
@ -9,7 +9,6 @@ from .shells import shell
|
||||
from .conf import settings
|
||||
from .const import DEFAULT_PRIORITY, ALL_ENABLED
|
||||
from .exceptions import EmptyCommand
|
||||
from .utils import compatibility_call
|
||||
|
||||
|
||||
class Command(object):
|
||||
@ -225,7 +224,7 @@ class Rule(object):
|
||||
|
||||
try:
|
||||
with logs.debug_time(u'Trying rule: {};'.format(self.name)):
|
||||
if compatibility_call(self.match, command):
|
||||
if self.match(command):
|
||||
return True
|
||||
except Exception:
|
||||
logs.rule_failed(self, sys.exc_info())
|
||||
@ -237,7 +236,7 @@ class Rule(object):
|
||||
:rtype: Iterable[CorrectedCommand]
|
||||
|
||||
"""
|
||||
new_commands = compatibility_call(self.get_new_command, command)
|
||||
new_commands = self.get_new_command(command)
|
||||
if not isinstance(new_commands, list):
|
||||
new_commands = (new_commands,)
|
||||
for n, new_command in enumerate(new_commands):
|
||||
@ -283,7 +282,7 @@ class CorrectedCommand(object):
|
||||
|
||||
"""
|
||||
if self.side_effect:
|
||||
compatibility_call(self.side_effect, old_cmd, self.script)
|
||||
self.side_effect(old_cmd, self.script)
|
||||
if settings.alter_history:
|
||||
shell.put_to_history(self.script)
|
||||
# This depends on correct setting of PYTHONIOENCODING by the alias:
|
||||
|
@ -9,7 +9,6 @@ from contextlib import closing
|
||||
from decorator import decorator
|
||||
from difflib import get_close_matches
|
||||
from functools import wraps
|
||||
from inspect import getargspec
|
||||
try:
|
||||
from pathlib import Path
|
||||
except ImportError:
|
||||
@ -245,27 +244,6 @@ def cache(*depends_on):
|
||||
cache.disabled = False
|
||||
|
||||
|
||||
def compatibility_call(fn, *args):
|
||||
"""Special call for compatibility with user-defined old-style rules
|
||||
with `settings` param.
|
||||
|
||||
"""
|
||||
fn_args_count = len(getargspec(fn).args)
|
||||
if fn.__name__ in ('match', 'get_new_command') and fn_args_count == 2:
|
||||
warn("Two arguments `{}` from rule `{}` is deprecated, please "
|
||||
"remove `settings` argument and use "
|
||||
"`from thefuck.conf import settings` instead."
|
||||
.format(fn.__name__, fn.__module__))
|
||||
args += (settings,)
|
||||
if fn.__name__ == 'side_effect' and fn_args_count == 3:
|
||||
warn("Three arguments `side_effect` from rule `{}` is deprecated, "
|
||||
"please remove `settings` argument and use `from thefuck.conf "
|
||||
"import settings` instead."
|
||||
.format(fn.__name__, fn.__module__))
|
||||
args += (settings,)
|
||||
return fn(*args)
|
||||
|
||||
|
||||
def get_installation_info():
|
||||
return pkg_resources.require('thefuck')[0]
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user