File tree Expand file tree Collapse file tree 2 files changed +21
-9
lines changed Expand file tree Collapse file tree 2 files changed +21
-9
lines changed Original file line number Diff line number Diff line change 11from __future__ import annotations
22
33import contextlib
4+ import inspect
45import logging
56import os
67import time
@@ -114,15 +115,26 @@ def __call__( # noqa: PLR0913
114115 msg += f"\n \t { param_name } (existing lock has { set_param } but { passed_param } was passed)"
115116 raise ValueError (msg )
116117
117- instance = super ().__call__ (
118- lock_file = lock_file ,
119- timeout = timeout ,
120- mode = mode ,
121- thread_local = thread_local ,
122- blocking = blocking ,
123- is_singleton = is_singleton ,
118+ # Workaround to make `__init__`'s params optional in subclasses
119+ # E.g. virtualenv changes the signature of the `__init__` method in the `BaseFileLock` class descendant
120+ # (https://github.com/tox-dev/filelock/pull/340)
121+
122+ all_params = {
123+ "lock_file" : lock_file ,
124+ "timeout" : timeout ,
125+ "mode" : mode ,
126+ "thread_local" : thread_local ,
127+ "blocking" : blocking ,
128+ "is_singleton" : is_singleton ,
124129 ** kwargs ,
125- )
130+ }
131+
132+ present_params = set (inspect .signature (cls .__init__ ).parameters ) # type: ignore[misc]
133+ 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
136+
137+ instance = super ().__call__ (** init_params )
126138
127139 if is_singleton :
128140 cls ._instances [str (lock_file )] = instance # type: ignore[attr-defined]
Original file line number Diff line number Diff line change 22
33from typing import TYPE_CHECKING
44
5- from virtualenv import cli_run
5+ from virtualenv import cli_run # type: ignore[import-untyped]
66
77if TYPE_CHECKING :
88 from pathlib import Path
You can’t perform that action at this time.
0 commit comments