Skip to content
Merged
Changes from 1 commit
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
Next Next commit
Fix TypeError: _CountedFileLock.__init__() got an unexpected keyword …
…argument 'timeout'
  • Loading branch information
kwist-sgr committed Jun 19, 2024
commit 734534f329e0fb72b4584fa1d57c4b83a55bc886
26 changes: 18 additions & 8 deletions src/filelock/_api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import contextlib
import inspect
import logging
import os
import time
Expand Down Expand Up @@ -114,15 +115,24 @@ def __call__( # noqa: PLR0913
msg += f"\n\t{param_name} (existing lock has {set_param} but {passed_param} was passed)"
raise ValueError(msg)

instance = super().__call__(
lock_file=lock_file,
timeout=timeout,
mode=mode,
thread_local=thread_local,
blocking=blocking,
is_singleton=is_singleton,
# Workaround to make `__init__`'s params optional in subclasses
# E.g. virtualenv changes the `__init__` signature of the `BaseFileLock` class
# (https://github.com/tox-dev/filelock/pull/340)

all_params = {
"lock_file": lock_file,
"timeout": timeout,
"mode": mode,
"thread_local": thread_local,
"blocking": blocking,
"is_singleton": is_singleton,
**kwargs,
)
}

present_params = set(inspect.signature(cls.__init__).parameters)
init_params = {key: value for key, value in all_params.items() if key in present_params}

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

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