Use a metaclass to implement the singleton pattern#340
Use a metaclass to implement the singleton pattern#340gaborbernat merged 8 commits intotox-dev:mainfrom kwist-sgr:main
Conversation
|
@kwist-sgr https://github.com/tox-dev/sphinx-autodoc-typehints/actions/runs/9583644379/job/26425402570 seems broke the world had to yank it... |
|
To be fair it seems virtualenv is violating the contract by not implementing the proper signature of |
|
The thing is that all other args past the lockfile should be optional... or they were, so without making it a breaking change we can't suddenly require downstream to have this optional args... |
|
Hmm actually never mind, that doesn't make sense with the error |
|
OK I understand @gaborbernat's explanation. Yeah looking further, beyond just the super call, the |
|
@gaborbernat Oh. I apologize. I'm going to create a fix |

Reason
More correct implementation of the
singletonpattern.There is a problem with the current implementation: class's
__init__to be called again wheneverlock_class(is_singleton=True)is called, which is at least not obvious (also, it'll lead to the re-initializing instance's internal objects, e.g.: virtualenv/util/lock.py)What was done in this PR
FileLockMeta/AsyncFileLockMetaused as metaclasses forBaseFileLock/BaseAsyncFileLock__init__method is called only onceRelated PRs