Skip to content

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

Open
maroux wants to merge 1 commit into
python:mainfrom
maroux:simplejson-encoder-default-any
Open

maroux wants to merge 1 commit into
python:mainfrom
maroux:simplejson-encoder-default-any

Conversation

@maroux

@maroux maroux commented Oct 1, 2026

Copy link
Copy Markdown

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

@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

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

This branch has not been deployed

No deployments
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