Skip to content

Reject unsupported subclass lock options #628

Closed

Description

@gaborbernat

Severity: High. A subclass can accept construction while filelock discards a requested safety policy.

Problem

FileLockMeta._create_instance()
filters constructor arguments by the parameter names present in the subclass __init__ signature.

This supports older subclasses with narrow signatures, but it has two failure modes:

  • A subclass with **kwargs does not receive base options because VAR_KEYWORD is not a named option.
  • A narrow subclass discards non-default values such as on_acquired, preserve_lock_file, fallback_to_soft,
    context_error_policy, and close_error_policy.

Construction succeeds even though the requested behavior is inactive. The metaclass also calls inspect.signature() for
each construction.

Required contract

Pass all supported base options when the subclass accepts **kwargs. For a narrow signature, omit unsupported options
only when the caller supplied the documented default. Raise TypeError for each unsupported non-default option.

Cache the inspected signature and accepted-option model per subclass after the forwarding rules are correct. The cache
must not change singleton argument comparison.

Verification

  • Define a virtualenv-style subclass with a narrow constructor and confirm that default construction still works.
  • Pass each non-default base option to that subclass and confirm that construction raises before acquisition.
  • Define a forwarding subclass with **kwargs and confirm that each option reaches BaseFileLock.
  • Cover direct subclasses of sync and async base locks.
  • Confirm that singleton reuse still rejects a changed hook object or policy.
  • Benchmark repeated construction before and after signature caching with the same interpreter.

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions