Conversation
Class N(int): pass; N(5) + 1 returns 6, N(5).bit_length() works,
isinstance(N(5), int) is True, {N(5): "a"}[5] returns "a", and
S("hi").upper() returns "HI". Same for str/list/dict/bytes
subclasses.
Builtin types stay as *object.BuiltinFunc; instead the subclass
instance carries a BuiltinValue payload built at construction time.
After dunder dispatch, binary/unary/compare/contains/getitem paths
unbox both operands so the type-specific Go switches handle them
transparently. Operator results are plain builtin types unless the
class overrides the dunder, matching CPython.
object.Class gets BuiltinBase + BuiltinMRO; object.Instance gets
BuiltinValue. __build_class__ detects builtin-type bases. Class call
path auto-constructs BuiltinValue from args when no user __init__.
isinstance/issubclass walk the BuiltinBase relation. getAttr falls
back to BuiltinValue so inherited methods work. instance hashes/eq/
repr/str/truthy fall through to the payload when no override.
Spec at notes/Spec/1500/1544_goipy_v0103_builtin_subclass_arith.md.
Fixture 349.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
class N(int): pass; N(5) + 1returns 6,N(5).bit_length()works,isinstance(N(5), int)is True,{N(5): "a"}[5]returns "a", andS("hi").upper()returns "HI". Same for str / list / dict / bytes subclasses.*object.BuiltinFunc. Subclass instances carry aBuiltinValuepayload constructed at instantiation; after every dunder dispatch the binary/unary/compare/contains/getitem paths callunboxBuiltinso the type-specific Go switches handle the unboxed operands. Results are plain builtin types unless the class overrides the dunder — matches CPython.notes/Spec/1500/1544_goipy_v0103_builtin_subclass_arith.md. v0.1.4 lands the typing fallout.Test plan
go build ./...go test ./vm/...internal/testdata/349_builtin_subclass_arith.py) matches CPython 3.14 byte-for-byte