Skip to content

[simplejson] Make JSONEncoder.default return Any, matching json.JSONEncoder - #16462

Merged
srittau merged 2 commits into
python:mainfrom
maroux:simplejson-encoder-default-any
Oct 30, 2026
Merged

srittau merged 2 commits into
python:mainfrom
maroux:simplejson-encoder-default-any

Conversation

@maroux

@maroux maroux commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

simplejson.JSONEncoder.default is declared -> Never, while the stdlib stub declares json.JSONEncoder.default as -> Any.

default is the hook subclasses override to serialise extra types, so it returns a value; only the base implementation raises. With -> Never, every override that returns something fails the override check. For example, this reports invalid-method-override under ty:

class DateTimeEncoder(simplejson.JSONEncoder):
    def default(self, o: Any) -> str:
        if isinstance(o, datetime):
            return o.isoformat()
        return super().default(o)

This changes the return type to Any, the same as json.JSONEncoder.default, and drops the now-unused Never import.

🤖 Generated with Claude Code

…ncoder

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

This comment has been minimized.

Comment thread stubs/simplejson/simplejson/encoder.pyi Resolved
@hoangchunghien

Copy link
Copy Markdown
Contributor

@maroux are you still planning to apply @srittau's suggestion? It is a one-line change. If you no longer have time, I'm happy to open a PR with it and credit you as co-author, unless you'd rather keep this one going.

Co-authored-by: Sebastian Rittau <sebastian.rittau@zfutura.de>
@maroux

maroux commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

@maroux are you still planning to apply @srittau's suggestion? It is a one-line change. If you no longer have time, I'm happy to open a PR with it and credit you as co-author, unless you'd rather keep this one going.

Whoops, had missed it, applied.

@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@srittau
srittau merged commit a746e49 into python:main Oct 30, 2026
74 checks passed
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.

3 participants