Skip to content

fix(soft-rw): isolate subclass singleton registries - #855

Merged
gaborbernat merged 3 commits into
tox-dev:mainfrom
AryanRG:fix/soft-rw-subclass-singletons
Oct 17, 2026
Merged

gaborbernat merged 3 commits into
tox-dev:mainfrom
AryanRG:fix/soft-rw-subclass-singletons

Conversation

@AryanRG

@AryanRG AryanRG commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Constructing a SoftReadWriteLock subclass on a path already used by the base class or a sibling can return the other class's cached object. This skips the requested subclass's initializer and overrides:

from filelock import SoftReadWriteLock

class CustomLock(SoftReadWriteLock):
    pass

base = SoftReadWriteLock("work.lock")
custom = CustomLock("work.lock")
assert type(custom) is CustomLock  # fails before this change

Give each concrete class its own weak singleton cache, reentrant mutex, and construction guard. Reset that state after fork and forward cooperative class-definition keywords. Same-class singleton reuse and recursive-construction rejection are preserved; separate classes still contend on the same underlying lock path.

Regression coverage includes all three construction orders, overlapping constructors across base/sibling/descendant classes, cooperative mixins, recursion and retry, concurrent same-class reuse, and child-process resets while another thread is constructing a subclass. The original three-order regression fails against the unchanged base.

Validation on macOS arm64:

  • Python 3.15 full suite, old-client compatibility enabled: 2,413 passed, 63 skipped; 100% line and branch coverage.
  • Python 3.11 sync/fork suites: 166 passed, 6 skipped.
  • Hooks for the changed files, type checking, and whitespace checks passed.

The full tox matrix and other operating systems/runtimes have not been run locally; hosted checks remain separate validation.

AI tools assisted with implementation, testing, and review.

@AryanRG
AryanRG marked this pull request as ready for review October 17, 2026 00:20
@gaborbernat
gaborbernat enabled auto-merge (squash) October 17, 2026 10:28
@gaborbernat
gaborbernat merged commit 9d15e38 into tox-dev:main Oct 17, 2026
44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants