8000 Fix `TypeError: _CountedFileLock.__init__() got an unexpected keyword argument 'timeout'` by kwist-sgr · Pull Request #345 · tox-dev/filelock · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix TypeError: _CountedFileLock.__init__() got an unexpected keyword argument 'timeout' #345

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

Merged
merged 4 commits into from
Jun 19, 2024
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
28 changes: 20 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,26 @@ 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 signature of the `__init__` method in the `BaseFileLock` class descendant
# (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) # 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)

if is_singleton:
cls._instances[str(lock_file)] = instance # type: ignore[attr-defined]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from typing import TYPE_CHECKING

from virtualenv import cli_run
from virtualenv import cli_run # type: ignore[import-untyped]

if TYPE_CHECKING:
from pathlib import Path
Expand Down
Loading
0