8000 beartype cannot check IServable, so two worker functions go unchecked and every test log carries the traceback · Issue #61 · nixidae/nixidae · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

beartype cannot check IServable, so two worker functions go unchecked and every test log carries the traceback #61

Closed

Description

@Lillecarl

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.

  1. Both functions are silently unchecked. Every other function in
    nanopynix gets beartype's runtime check under test; these two do not, and
    nothing says so. A wrong argument type to worker_service_factory -- which
    is the seam the namespaced overlay worker will grow -- passes a run that
    would catch it anywhere else.
  2. The traceback floods every test log. _worker.py is 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_31 failure 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 -- the cast exists 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.protocols and rpc/client/_session.py all
    declare Protocol classes without @runtime_checkable and 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. IServable is the only one, and it is the only
    Protocol here that comes from another project.

Acceptance criteria

  • Importing nanopynix.rpc.worker._worker under 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.

Activity

  1. Lillecarl commented on Jul 30, 2026

    @Lillecarl
    ContributorAuthor

    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.py already named both, with
    reasons, in an UNDECORATABLE allowlist, and
    test_no_callable_is_silently_undecoratable_beyond_the_known_list asserts in
    both directions -- so a new hole fails the suite, and a hole that gets fixed
    also fails it, on the stale assertion. That gate is what turned this from a
    change 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_factory builds three concrete handlers
    and already cast its list to list[IServable] -- so the annotation described
    the caller's contract rather than the code, and the cast was the tell.

    Fixed by naming the union of the three handlers. That is checkable, the cast
    is gone, and Server still accepts them because they satisfy IServable
    structurally.

    One thing left over, in grpclib-transports rather than here.
    serve_stdio declares handlers: list[IServable], and list is invariant, so
    that one call site still needs a cast. Its sibling
    serve_multiprocessing_endpoint declares Collection[IServable] and needs
    nothing. Widening serve_stdio to Collection upstream would remove the last
    mention of the protocol from this repository.

    Co-Authored-By: Claude Opus 5 noreply@anthropic.com

  2. added
    source: nanopynix
    on Oct 19, 2026
  3. added theissue type on Oct 19, 2026
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

    source: nanopynix

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0