Repository navigation
Closed
Labels
source: nanopynixConcerns the nanopynix source
Description
grpclib._typing.IServable is a Protocol that is not
@runtime_checkable, so beartype cannot build an isinstance check for it.
Two functions in rpc/worker/_worker.py are annotated with it:
worker_service_factory(...) -> list[IServable](_worker.py:488)_shutdown_worker(handlers: list[IServable]) -> None(_worker.py:551)
beartype emits a BeartypeClawDecorWarning while decorating each one, and
leaves the function undecorated:
beartype.roar.BeartypeDecorHintPep3119Exception: Function
nanopynix.rpc.worker._worker.worker_service_factory() return wrapper parameter
<class 'grpclib._typing.IServable'> uncheckable at runtime (i.e., not passable
as second parameter to isinstance(), due to raising "TypeError: Instance and
class checks can only be used with @runtime_checkable protocols" from
metaclass _ProtocolMeta.__instancecheck__() method).
Measured
Reproduced with the same bootstrap the test suite installs:
direnv exec . python -c "
import sys; sys.path.insert(0, 'tests/_subprocess_startup')
import beartype_bootstrap; beartype_bootstrap.install()
import nanopynix.rpc.worker._worker as w
print('imported OK'); print(w.worker_service_factory())
"
The import succeeds and the factory works. beartype's claw hook prints
the traceback and leaves the function undecorated.
Why it matters
Two problems, and the second is the one that cost time.
- Both functions are silently unchecked. Every other function in
nanopynixgets beartype's runtime check under test; these two do not, and
nothing says so. A wrong argument type toworker_service_factory-- which
is the seam the namespaced overlay worker will grow -- passes a run that
would catch it anywhere else. - The traceback floods every test log.
_worker.pyis imported in each
worker subprocess, so two multi-frame tracebacks land in the captured
output of any test that starts a worker. When a real failure occurs, this
is what the log shows first. It was in the way while reading the
test-local-nix_2_31failure of tests: the fetch-scope override test fails on Nix 2.31, and CI never ran it #60.
Neither is a crash, which is why it has survived.
What to decide
- Whether to keep the annotation and exclude these two functions explicitly.
An exclusion must say why, per the repository's rule on suppressions. - Or to annotate the concrete handler types instead. The factory already
casts a list of three known handler classes
(WorkerServiceHandler,StoreServiceHandler,EvalServiceHandler), so a
union of those is both checkable and more honest than a private grpclib
protocol -- thecastexists precisely because the protocol says less than
the code knows.
Nothing else is affected. Measured, so the next reader does not repeat it:
nanopynix.logging,nanopynix.protocolsandrpc/client/_session.pyall
declareProtocolclasses without@runtime_checkableand all import
quietly, because none of them is named in a checked annotation.
_WorkerDispatch(_grpc_util.py:55) is quiet too -- it is a TypeVar bound,
not a parameter type.IServableis the only one, and it is the only
Protocolhere that comes from another project.
Acceptance criteria
- Importing
nanopynix.rpc.worker._workerunder the beartype bootstrap prints
nothing. - Both functions are either checked by beartype, or excluded with a reason at
the site. - A test asserts that the import is quiet, so the noise cannot come back.
Tests
- Import the module under
beartype_bootstrap.install()in a subprocess and
assert that stderr is empty. A subprocess, because the claw hook is global
and the module is already imported by the time any test runs. - If the union is chosen, a test that passes a wrong type and gets a
BeartypeCallHintParamViolation-- proving the check is live rather than
merely quiet.
Found while reading CI logs for #57.
Metadata
Metadata
Assignees
Labels
source: nanopynixConcerns the nanopynix source
Activity
Lillecarl commentedon Jul 30, 2026
Correction to the issue body before I close it.
"Both functions are silently unchecked ... and nothing says so" was wrong.
tests/nanopynix/test_beartype_instrumentation.pyalready named both, withreasons, in an
UNDECORATABLEallowlist, andtest_no_callable_is_silently_undecoratable_beyond_the_known_listasserts inboth directions -- so a new hole fails the suite, and a hole that gets fixed
also fails it, on the
staleassertion. That gate is what turned this from achange into a proof. The rest of the issue stands: the two functions were
genuinely unchecked, and the warning genuinely floods every worker-starting
test's captured output.
The recorded reason was also wrong, and that is the interesting part. The
allowlist said "not fixable here: the decorator would have to go on grpclib's
declaration". The fix was never to make their protocol runtime-checkable. It
was to stop naming it.
worker_service_factorybuilds three concrete handlersand already
castits list tolist[IServable]-- so the annotation describedthe caller's contract rather than the code, and the
castwas the tell.Fixed by naming the union of the three handlers. That is checkable, the
castis gone, and
Serverstill accepts them because they satisfyIServablestructurally.
One thing left over, in grpclib-transports rather than here.
serve_stdiodeclareshandlers: list[IServable], andlistis invariant, sothat one call site still needs a cast. Its sibling
serve_multiprocessing_endpointdeclaresCollection[IServable]and needsnothing. Widening
serve_stdiotoCollectionupstream would remove the lastmention of the protocol from this repository.
Co-Authored-By: Claude Opus 5 noreply@anthropic.com
fix(rpc): name the worker handlers so beartype can check them
pynixd(tests): the start failure test looks for threads after the loo…