(
cls: type[_T], lock_file: str | os.PathLike[str], params: dict[str, _LockInitValue | _ExtraValue]
)
| 446 | raise ValueError(msg) |
| 447 | |
| 448 | def _create_instance( |
| 449 | cls: type[_T], lock_file: str | os.PathLike[str], params: dict[str, _LockInitValue | _ExtraValue] |
| 450 | ) -> _T: |
| 451 | model = _init_parameter_model(cls) |
| 452 | if model.accepts_kwargs: |
| 453 | return super().__call__(lock_file, **params) |
| 454 | |
| 455 | unsupported = sorted( |
| 456 | name |
| 457 | for name, value in params.items() |
| 458 | if name not in model.accepted_params |
| 459 | and ((parameter := model.default_params.get(name)) is None or value != parameter.default) |
| 460 | ) |
| 461 | if unsupported: |
| 462 | msg = f"{cls.__name__} does not support non-default lock options: {', '.join(unsupported)}" |
| 463 | raise TypeError(msg) |
| 464 | # virtualenv narrows a BaseFileLock descendant's signature; omit base defaults it does not accept (#340). |
| 465 | return super().__call__( |
| 466 | lock_file, |
| 467 | **{name: value for name, value in params.items() if name in model.accepted_params}, |
| 468 | ) |
| 469 | |
| 470 | |
| 471 | _INIT_PARAMETER_MODELS: Final[WeakKeyDictionary[type[BaseFileLock], _InitParameterModel]] = WeakKeyDictionary() |
no test coverage detected