File tree 2 files changed +21
-9
lines changed
2 files changed +21
-9
lines changed Original file line number Diff line number Diff line change 1
1
from __future__ import annotations
2
2
3
3
import contextlib
4
+ import inspect
4
5
import logging
5
6
import os
6
7
import time
@@ -114,15 +115,26 @@ def __call__( # noqa: PLR0913
114
115
msg += f"\n \t { param_name } (existing lock has { set_param } but { passed_param } was passed)"
115
116
raise ValueError (msg )
116
117
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 ,
124
129
** 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 )
126
138
127
139
if is_singleton :
128
140
cls ._instances [str (lock_file )] = instance # type: ignore[attr-defined]
Original file line number Diff line number Diff line change 2
2
3
3
from typing import TYPE_CHECKING
4
4
5
- from virtualenv import cli_run
5
+ from virtualenv import cli_run # type: ignore[import-untyped]
6
6
7
7
if TYPE_CHECKING :
8
8
from pathlib import Path
You can’t perform that action at this time.
0 commit comments