Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/filelock/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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]
Expand Down
10 changes: 10 additions & 0 deletions tests/test_filelock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"