Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: tox-dev/filelock
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 3.15.3
Choose a base ref
...
head repository: tox-dev/filelock
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 3.15.4
Choose a head ref
  • 1 commit
  • 2 files changed
  • 1 contributor

Commits on Jun 22, 2024

  1. Pass file_lock as positional argument (#347)

    kwist-sgr authored Jun 22, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    9a979df View commit details
Showing with 12 additions and 5 deletions.
  1. +2 −5 src/filelock/_api.py
  2. +10 −0 tests/test_filelock.py
7 changes: 2 additions & 5 deletions src/filelock/_api.py
Original file line number Diff line number Diff line change
@@ -120,7 +120,6 @@ def __call__( # noqa: PLR0913
# (https://github.com/tox-dev/filelock/pull/340)

all_params = {
"lock_file": lock_file,
"timeout": timeout,
"mode": mode,
"thread_local": thread_local,
@@ -129,12 +128,10 @@ def __call__( # noqa: PLR0913
**kwargs,
}

present_params = set(inspect.signature(cls.__init__).parameters) # type: ignore[misc]
present_params = inspect.signature(cls.__init__).parameters # type: ignore[misc]
init_params = {key: value for key, value in all_params.items() if key in present_params}
# The `lock_file` parameter is required
init_params["lock_file"] = lock_file

instance = super().__call__(**init_params)
instance = super().__call__(lock_file, **init_params)

if is_singleton:
cls._instances[str(lock_file)] = instance # type: ignore[attr-defined]
10 changes: 10 additions & 0 deletions tests/test_filelock.py
Original file line number Diff line number Diff line change
@@ -802,3 +802,13 @@ def __init__(self, *args: Any, **kwargs: Any) -> None: # noqa: ANN401

assert lock1 is lock2
assert init_calls == 1


def test_file_lock_positional_argument(tmp_path: Path) -> None:
class FilePathLock(FileLock):
def __init__(self, file_path: str) -> None:
super().__init__(file_path + ".lock")

lock_path = tmp_path / "a"
lock = FilePathLock(str(lock_path))
assert lock.lock_file == str(lock_path) + ".lock"