Skip to content

gh-156062: Fix SynchronizedBase instantiation without a lock or a ctx - #156063

Open
ekanshul wants to merge 1 commit into
python:mainfrom
ekanshul:fix-sharedctypes-synchronized-default-context
Open

gh-156062: Fix SynchronizedBase instantiation without a lock or a ctx#156063
ekanshul wants to merge 1 commit into
python:mainfrom
ekanshul:fix-sharedctypes-synchronized-default-context

Conversation

@ekanshul

Copy link
Copy Markdown

SynchronizedBase.__init__ calls get_context(force=True) when it is given neither a lock nor a ctx, but get_context() has never accepted a force argument (set_start_method() does). So instantiating Synchronized, SynchronizedArray or SynchronizedString directly, without a lock or a context, raised:

TypeError: DefaultContext.get_context() got an unexpected keyword argument 'force'

Value(), Array() and synchronized() always resolve a context and pass it down, which is why this went unnoticed since the line was written in b1694cf (bpo-18999). The fix mirrors what synchronized() does a few lines above: call get_context().

The new test instantiates each of the three wrapper classes without a lock or a context and exercises the resulting lock. Without the fix all three subtests fail with the TypeError above; with it they pass under the spawn and forkserver start methods (the fork variants are skipped on macOS, where I ran this).

Found by running pylint over the standard library (unexpected-keyword-arg).

… a ctx

``SynchronizedBase.__init__`` called ``get_context(force=True)`` when it
was given neither a lock nor a context, but ``get_context()`` has never
accepted a ``force`` argument (``set_start_method()`` does), so
instantiating ``Synchronized``, ``SynchronizedArray`` or
``SynchronizedString`` directly raised ``TypeError``. The module-level
helpers always pass a context down, which is why this went unnoticed since
the contexts were introduced.
@ekanshul
ekanshul requested a review from gpshead as a code owner August 19, 2026 17:32
@python-cla-bot

Copy link
Copy Markdown

The following commit authors need to sign the Contributor License Agreement:

CLA not signed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant