Skip to content

v0.1.2: builtin types as classes (V2 surface)#269

Merged
tamnd merged 1 commit into
mainfrom
v0.1.2
Apr 29, 2026
Merged

v0.1.2: builtin types as classes (V2 surface)#269
tamnd merged 1 commit into
mainfrom
v0.1.2

Conversation

@tamnd

@tamnd tamnd commented Apr 29, 2026

Copy link
Copy Markdown
Owner

Summary

V2 part 1 of 3: builtin types (int, str, bool, float, list, tuple, dict, set, frozenset, bytes, bytearray, complex, memoryview, type) now satisfy type(int) is type, isinstance(int, type), issubclass(bool, int), and expose __mro__ / __name__ / __bases__ / __qualname__ / __module__.

Surface only — subclass arithmetic (class N(int): ...) is V2 part 2 (v0.1.3); typing fallout is V2 part 3 (v0.1.4).

  • vm/ops.go: builtinTypeNames, builtinTypeBases, isBuiltinTypeName, isBuiltinSubclass.
  • vm/builtins.go: wireBuiltinTypeAttrs decorates each builtin-type BuiltinFunc with class-shape attrs; type() is a self-referential BuiltinFunc; isinstance and issubclass learn the BuiltinFunc-as-class form.
  • internal/testdata/348_builtin_types_surface.py covers type(x) is T, type(T) is type, isinstance(T, type), issubclass matrix, name/qualname/module, __mro__, __bases__.
  • internal/testdata/281_builtins.expected.txt regenerated — it had captured pre-V2 issubclass(bool, int) → False; now correctly True.

Spec: notes/Spec/1500/1543_goipy_v0102_builtin_types_surface.md
Roadmap: notes/Spec/1500/1541_goipy_v01x_roadmap.md (V2)

Test plan

  • go build ./... clean
  • go test ./... green (including 348 + the regenerated 281 expected)
  • python3.14 -m compileall -b internal/testdata/348_builtin_types_surface.py && go run ./cmd/goipy internal/testdata/348_builtin_types_surface.pyc matches CPython output

`type(int) is type`, `isinstance(int, type)`, `issubclass(bool, int)`,
`int.__mro__` / `__name__` / `__bases__` / `__qualname__` / `__module__`
all behave like CPython now. Builtin types stay as `*object.BuiltinFunc`
under the hood (no dispatch core changes); `wireBuiltinTypeAttrs`
decorates them with class-shape metadata, and `type()` is a self-
referential BuiltinFunc that returns the registered type for builtins.

Subclass arithmetic (`class N(int): ...`) is V2 part 2, scheduled for
v0.1.3. typing.get_type_hints fallout is V2 part 3, scheduled for
v0.1.4.

Fixture 348 covers the surface across every builtin type. The pre-V2
281_builtins.expected.txt had captured a buggy goipy answer for
`issubclass(bool, int)`; regenerated from CPython.

Spec: notes/Spec/1500/1543_goipy_v0102_builtin_types_surface.md
Roadmap: notes/Spec/1500/1541_goipy_v01x_roadmap.md (V2)
@tamnd tamnd merged commit 24c9cd8 into main Apr 29, 2026
1 check passed
@tamnd tamnd deleted the v0.1.2 branch April 29, 2026 09:14
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