From 195855c77fa3540baa5ffc030d741eb9fbbb122d Mon Sep 17 00:00:00 2001 From: Sebastian Bank Date: Thu, 21 Mar 2024 08:07:14 +0100 Subject: [PATCH] Revert "fix number of positional arguments in deprecation warning messages" This reverts commit e5578d39009469df2b7c6743458970643e228226. --- graphviz/_tools.py | 9 ++------- graphviz/saving.py | 2 +- graphviz/sources.py | 6 +++--- tests/backend/test_piping.py | 2 +- tests/backend/test_rendering.py | 2 +- tests/test_all_classes.py | 2 +- tests/test_sources.py | 9 ++++----- 7 files changed, 13 insertions(+), 19 deletions(-) diff --git a/graphviz/_tools.py b/graphviz/_tools.py index 8343fdf169..018425c9f2 100644 --- a/graphviz/_tools.py +++ b/graphviz/_tools.py @@ -106,7 +106,6 @@ def promote_pathlike_directory(directory: typing.Union[os.PathLike, str, None], def deprecate_positional_args(*, supported_number: int, - ignore_argnames: typing.Sequence[str] = ('cls', 'self'), category: typing.Type[Warning] = PendingDeprecationWarning, stacklevel: int = 1): """Mark supported_number of positional arguments as the maximum. @@ -114,8 +113,6 @@ def deprecate_positional_args(*, Args: supported_number: Number of positional arguments for which no warning is raised. - ignore_argnames: Name(s) of arguments to ignore - ('cls' and 'self' by default). category: Type of Warning to raise or None to return a nulldecorator returning the undecorated function. @@ -146,8 +143,7 @@ def nulldecorator(func): def decorator(func): signature = inspect.signature(func) argnames = [name for name, param in signature.parameters.items() - if param.kind == inspect.Parameter.POSITIONAL_OR_KEYWORD - and name not in ignore_argnames] + if param.kind == inspect.Parameter.POSITIONAL_OR_KEYWORD] log.debug('deprecate positional args: %s.%s(%r)', func.__module__, func.__qualname__, argnames[supported_number:]) @@ -166,8 +162,7 @@ def wrapper(*args, **kwargs): wanted = ', '.join(f'{name}={value!r}' for name, value in deprecated.items()) warnings.warn(f'The signature of {func.__name__} will be reduced' - f' to {supported_number} positional arg' - f"{'s' if supported_number > 1 else ''}" + f' to {supported_number} positional args' f' {list(supported)}: pass {wanted}' ' as keyword arg(s)', stacklevel=stacklevel, diff --git a/graphviz/saving.py b/graphviz/saving.py index 48a73bcd48..0a95e8f523 100644 --- a/graphviz/saving.py +++ b/graphviz/saving.py @@ -50,7 +50,7 @@ def filepath(self) -> str: """The target path for saving the DOT source file.""" return os.path.join(self.directory, self.filename) - @_tools.deprecate_positional_args(supported_number=1) + @_tools.deprecate_positional_args(supported_number=2) def save(self, filename: typing.Union[os.PathLike, str, None] = None, directory: typing.Union[os.PathLike, str, None] = None, *, skip_existing: typing.Optional[bool] = False) -> str: diff --git a/graphviz/sources.py b/graphviz/sources.py index bd6cc5d875..12ec163102 100644 --- a/graphviz/sources.py +++ b/graphviz/sources.py @@ -39,7 +39,7 @@ class Source(rendering.Render, saving.Save, """ @classmethod - @_tools.deprecate_positional_args(supported_number=1) + @_tools.deprecate_positional_args(supported_number=2) def from_file(cls, filename: typing.Union[os.PathLike, str], directory: typing.Union[os.PathLike, str, None] = None, format: typing.Optional[str] = None, @@ -73,7 +73,7 @@ def from_file(cls, filename: typing.Union[os.PathLike, str], renderer=renderer, formatter=formatter, loaded_from_path=filepath) - @_tools.deprecate_positional_args(supported_number=1) + @_tools.deprecate_positional_args(supported_number=2) def __init__(self, source: str, filename: typing.Union[os.PathLike, str, None] = None, directory: typing.Union[os.PathLike, str, None] = None, @@ -122,7 +122,7 @@ def source(self) -> str: source += '\n' return source - @_tools.deprecate_positional_args(supported_number=1) + @_tools.deprecate_positional_args(supported_number=2) def save(self, filename: typing.Union[os.PathLike, str, None] = None, directory: typing.Union[os.PathLike, str, None] = None, *, skip_existing: typing.Optional[bool] = None) -> str: diff --git a/tests/backend/test_piping.py b/tests/backend/test_piping.py index 3c2f63338e..1db421cb63 100644 --- a/tests/backend/test_piping.py +++ b/tests/backend/test_piping.py @@ -75,7 +75,7 @@ def test_pipe_pipe_invalid_data_mocked(mocker, sentinel, mock_run, quiet): reason='https://gitlab.com/graphviz/graphviz/-/issues/1269'))]) def test_pipe(capsys, engine, format_, renderer, formatter, pattern, data=b'graph { spam }'): - with pytest.deprecated_call(match=r'3 positional args'): + with pytest.deprecated_call(): out = graphviz.pipe(engine, format_, data, renderer, formatter).decode('ascii') diff --git a/tests/backend/test_rendering.py b/tests/backend/test_rendering.py index ed3531f300..348af38bbf 100644 --- a/tests/backend/test_rendering.py +++ b/tests/backend/test_rendering.py @@ -60,7 +60,7 @@ def test_render(capsys, tmp_path, engine, format_, renderer, formatter, assert lpath.write_bytes(data) == len(data) == lpath.stat().st_size rendered = lpath.with_suffix(f'{lpath.suffix}.{expected_suffix}') - with pytest.deprecated_call(match=r'3 positional args'): + with pytest.deprecated_call(): result = graphviz.render(engine, format_, str(lpath), renderer, formatter) diff --git a/tests/test_all_classes.py b/tests/test_all_classes.py index f8e19b966a..74bf98c3ae 100644 --- a/tests/test_all_classes.py +++ b/tests/test_all_classes.py @@ -210,7 +210,7 @@ def test_save_mocked(mocker, dot, filename='nonfilename', directory='nondirector mock_makedirs = mocker.patch('os.makedirs', autospec=True) mock_open = mocker.patch('builtins.open', mocker.mock_open()) - with pytest.deprecated_call(match=r'1 positional arg\b'): + with pytest.deprecated_call(): assert dot.save(filename, directory) == dot.filepath assert dot.filename == filename diff --git a/tests/test_sources.py b/tests/test_sources.py index f4b1521dc8..a00a599454 100644 --- a/tests/test_sources.py +++ b/tests/test_sources.py @@ -42,23 +42,22 @@ def test_filepath(platform, source): def test_from_file(tmp_path, filename='hello.gv', directory='source_hello', - data='digraph { hello -> world }', encoding='utf-8', - deprecation_match=r'1 positional arg\b'): + data='digraph { hello -> world }', encoding='utf-8'): lpath = tmp_path / directory lpath.mkdir() (lpath / filename).write_text(data, encoding=encoding) - with pytest.deprecated_call(match=deprecation_match): + with pytest.deprecated_call(): source = graphviz.Source.from_file(filename, str(lpath)) assert source.encoding == 'utf-8' - with pytest.deprecated_call(match=deprecation_match): + with pytest.deprecated_call(): source = graphviz.Source.from_file(filename, str(lpath), encoding=None) assert source.encoding == locale.getpreferredencoding() renderer = 'xdot' formatter = 'core' - with pytest.deprecated_call(match=deprecation_match): + with pytest.deprecated_call(): source = graphviz.Source.from_file(filename, str(lpath), encoding=encoding, renderer=renderer,