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

Add stacklevel to deprecation warnings for argument name change #121

Merged
merged 2 commits into from
Dec 26, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/filelock/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def acquire(
self,
timeout: Optional[float] = None,
poll_interval: float = 0.05,
*,
gaborbernat marked this conversation as resolved.
Show resolved Hide resolved
poll_intervall: Optional[float] = None,
) -> AcquireReturnProxy:
"""
Expand Down Expand Up @@ -138,8 +139,8 @@ def acquire(

.. versionchanged:: 2.0.0

This method returns now a *proxy* object instead of *self*, so that it can be used in a with statement \
without side effects.
This method returns now a *proxy* object instead of *self*,
so that it can be used in a with statement without side effects.

"""
# Use the default timeout, if no timeout is provided.
Expand All @@ -148,7 +149,7 @@ def acquire(

if poll_intervall is not None:
msg = "use poll_interval instead of poll_intervall"
warnings.warn(msg, DeprecationWarning)
warnings.warn(msg, DeprecationWarning, stacklevel=2)
poll_interval = poll_intervall

# Increment the number right at the beginning. We can still undo it, if something fails.
Expand Down
11 changes: 9 additions & 2 deletions tests/test_filelock.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import sys
import threading
from contextlib import contextmanager
from inspect import getframeinfo, stack
from pathlib import Path, PurePath
from stat import S_IWGRP, S_IWOTH, S_IWUSR
from types import TracebackType
Expand Down Expand Up @@ -357,5 +358,11 @@ def test_poll_intervall_deprecated(lock_type: Type[BaseFileLock], tmp_path: Path
lock_path = tmp_path / "a"
lock = lock_type(str(lock_path))

with pytest.deprecated_call(match="use poll_interval instead of poll_intervall"):
lock.acquire(poll_intervall=0.05)
with pytest.deprecated_call(match="use poll_interval instead of poll_intervall") as checker:
lock.acquire(poll_intervall=0.05) # the deprecation warning will be captured by the checker
frameinfo = getframeinfo(stack()[0][0]) # get frameinfo of current file and lineno (+1 than the above lineno)
for warning in checker:
XuehaiPan marked this conversation as resolved.
Show resolved Hide resolved
if warning.filename == frameinfo.filename and warning.lineno + 1 == frameinfo.lineno: # pragma: no cover
break
else: # pragma: no cover
pytest.fail("No warnings of stacklevel=2 matching.")
4 changes: 4 additions & 0 deletions whitelist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,7 @@ unlck
util
win32
wronly
stacklevel
frameinfo
getframeinfo
lineno