Skip to content

Give ShapeSerializer.flush an explicit no-op body - #1018

Open
jonathan343 wants to merge 2 commits into
chore/add-pyreflyfrom
fix/pyrefly-flush
Open

jonathan343 wants to merge 2 commits into
chore/add-pyreflyfrom
fix/pyrefly-flush

Conversation

@jonathan343

Copy link
Copy Markdown
Contributor

Note

Stacked on #1017, targeting chore/add-pyrefly so this PR contains only the flush fix. I will retarget to develop after #1017 merges.

Summary

ShapeSerializer.flush has only a docstring for its body. At runtime that makes it a no-op default, and 31 of the 36 serializers in this repo rely on it, including SpecificShapeSerializer and InterceptingSerializer. Type checkers read a protocol method with an empty body as abstract instead. mypy and pyrefly therefore reject any serializer that inherits flush without overriding it, both here and in user code that subclasses these base classes. Pyright doesn't apply this rule, so CI never reported it.

This gives flush a return None body and documents the default in its docstring, the same way IdentityResolver.invalidate and AuthScheme.event_signer do. pass and ... count as empty bodies, so they would not fix it. Runtime behavior is unchanged. The fix removes 68 of the 162 entries in pyrefly-baseline.json.

Before / After

from smithy_core.schemas import Schema
from smithy_core.serializers import SpecificShapeSerializer


class StringRecorder(SpecificShapeSerializer):
    def __init__(self) -> None:
        self.values: list[str] = []

    def write_string(self, schema: Schema, value: str) -> None:
        self.values.append(value)


recorder = StringRecorder()

Before (mypy 2.4.1, then pyrefly 1.5.2)

repro.py:13: error: Cannot instantiate abstract class "StringRecorder" with abstract attribute "flush"  [abstract]
repro.py:13: note: "flush" is implicitly abstract because it has an empty function body. If it is not meant to be abstract, explicitly `return` or `return None`.
Found 1 error in 1 file (checked 1 source file)
ERROR repro.py:13:26-28: Cannot instantiate `StringRecorder` because the following members are abstract: `flush` [bad-instantiation]

After

Success: no issues found in 1 source file
 INFO 0 errors

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@jonathan343
jonathan343 marked this pull request as ready for review December 6, 2026 07:40
@jonathan343
jonathan343 requested a review from a team as a code owner December 6, 2026 07:40
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.

1 participant