Skip to content

Commit 9a979df

Browse files
authored
Pass file_lock as positional argument (#347)
1 parent 3a79343 commit 9a979df

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

Diff for: src/filelock/_api.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ def __call__( # noqa: PLR0913
120120
# (https://github.com/tox-dev/filelock/pull/340)
121121

122122
all_params = {
123-
"lock_file": lock_file,
124123
"timeout": timeout,
125124
"mode": mode,
126125
"thread_local": thread_local,
@@ -129,12 +128,10 @@ def __call__( # noqa: PLR0913
129128
**kwargs,
130129
}
131130

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

137-
instance = super().__call__(**init_params)
134+
instance = super().__call__(lock_file, **init_params)
138135

139136
if is_singleton:
140137
cls._instances[str(lock_file)] = instance # type: ignore[attr-defined]

Diff for: tests/test_filelock.py

+10
Original file line numberDiff line numberDiff line change
@@ -802,3 +802,13 @@ def __init__(self, *args: Any, **kwargs: Any) -> None: # noqa: ANN401
802802

803803
assert lock1 is lock2
804804
assert init_calls == 1
805+
806+
807+
def test_file_lock_positional_argument(tmp_path: Path) -> None:
808+
class FilePathLock(FileLock):
809+
def __init__(self, file_path: str) -> None:
810+
super().__init__(file_path + ".lock")
811+
812+
lock_path = tmp_path / "a"
813+
lock = FilePathLock(str(lock_path))
814+
assert lock.lock_file == str(lock_path) + ".lock"

0 commit comments

Comments
 (0)