Skip to content

3.12 compliance fixes and Updates#4

Merged
jgarzik merged 16 commits intomainfrom
updates
Mar 18, 2026
Merged

3.12 compliance fixes and Updates#4
jgarzik merged 16 commits intomainfrom
updates

Conversation

@jgarzik
Copy link
Copy Markdown
Owner

@jgarzik jgarzik commented Mar 18, 2026

No description provided.

jgarzik and others added 16 commits March 17, 2026 23:51
…add test_unary + test_pow

Track A fixes (6 un-skips):
- isinstance() arg2 validation: raises TypeError for non-type args
- issubclass() arg1/arg2 validation: raises TypeError for non-class args
- issubclass() tuple arg support: issubclass(cls, (type1, type2))
- Accept type_type, user_type_metatype, and exc_metatype as valid metatypes
- list.__setitem__ with string key: raise TypeError instead of segfault
- Default tp_base to object_type for classes without explicit base

Track B (2 new CPython tests, 0 skips):
- test_unary.py: unary +, -, ~ operators (4 tests)
- test_pow.py: pow() and ** operator (9 tests)

Infrastructure fixes:
- builtin pow() delegates to int_power for GMP overflow correctness
- 3-arg pow() negative modulus: Python-compatible remainder adjustment
- 3-arg pow() exp=0: apply final modulus (pow(x,0,mod) = 1 % mod)
- assertAlmostEqual/assertNotAlmostEqual added to unittest

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…_contains

Fixes:
- CONTAINS_OP tp_iter fallback: iterate via tp_iter when sq_contains
  and __contains__ dunder are unavailable (enables 'in' for range, etc.)
- CONTAINS_OP __getitem__ fallback: iterate via __getitem__(0,1,2,...)
  catching IndexError (enables 'in' for classes with only __getitem__)
- str_contains: validate substr is a string before accessing data
  (fixes segfault on `None in 'abc'`)

New test (0 skips):
- test_contains.py: 'in' operator for custom classes, builtins, strings (4 tests)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…kips

New exception type:
- UnboundLocalError (subclass of NameError) for LOAD_FAST_CHECK and LOAD_DEREF

New function attribute:
- func.__qualname__ reads co_qualname from code object

Formatted error messages:
- "name 'X' is not defined" (was "name not found") in LOAD_GLOBAL/LOAD_NAME
- "f() takes from N to M positional arguments but K were given"
  (was "function takes too many positional arguments") with qualname,
  min/max arg counts, and actual count

Un-skipped tests:
- test_scope.testUnboundLocal — catchable UnboundLocalError
- test_keywordonlyarg.testTooManyPositionalErrorMessage — __qualname__ + message format
- test_keywordonlyarg.test_default_evaluation_order — NameError message format

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Bug fixes:
- CALL_INTRINSIC_1 LIST_TO_TUPLE: remove stale mov rbx,rax that clobbered
  bytecode IP register, causing crash after star-unpacking in calls
- repr_push: raise RecursionError when repr stack depth exceeds 64
  (was silently ignoring, leading to stack overflow segfault)

Un-skipped tests:
- test_keywordonlyarg.testFunctionCall — star-unpacking now works
- test_augassign.testSequences — slice augmented assignment works (stale skip)
- list_tests.test_repr_deep — RecursionError on deeply nested list repr

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…comps, raise, class

Track B imports (all passing, minimal skips):
- test_exception_variations.py: 15 tests, 0 skips — try/except/else/finally combos
- test_genexps.py: 14 tests, 0 skips — generator expressions
- test_listcomps.py: 15 tests, 0 skips — list/dict/set comprehensions
- test_raise.py: 16 tests, 2 skips — raise statement, reraise, except filtering
- test_class.py: 24 tests, 0 skips — class creation, dunders, inheritance

Total CPython test suites: 25 (up from 20)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… skips)

Bug fix:
- COMPARE_OP identity fallback: check both payload AND tag for equality.
  None (payload=0, TAG_NONE) was comparing equal to SmallInt 0 (payload=0,
  TAG_SMALLINT) because only payload was checked.

New test:
- test_compare.py: int, float, string, list, tuple, set, dict, None, bool
  comparisons plus custom __eq__/__ne__/__lt__/__gt__ (15 tests)

Total CPython test suites: 26

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…st_opcodes, test_baseexception

Infrastructure fixes:
- PyExceptionObject.exc_dict: new field for arbitrary instance attributes
  on exception objects (both built-in and user-defined exception types)
- exc_setattr: store custom attributes in exc_dict (creates dict on demand)
- exc_getattr: check exc_dict after type dict (fix: skip to exc_dict when
  type dict is NULL instead of jumping to not_found)
- BaseException.tp_base = object_type (enables issubclass(Exception, object))
- exc_subclass_call: call user-defined __init__ after exc_type_call
- PyExceptionGroupObject: add exc_dict field (keeps struct alignment)
- Wire exc_getattr/exc_setattr on user-defined exception subclasses

New tests (0 skips except noted):
- test_with.py: 12 tests — with statement, context managers, nesting
- test_opcodes.py: 11 tests — try/except loops, unpacking, format, augmented assign
- test_baseexception.py: 15 tests, 2 skips — exception hierarchy, args, custom exceptions

Total CPython test suites: 29

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…roperty, test_string

Infrastructure:
- builtin next(iterator, default): return default on StopIteration
  instead of raising (2-arg form)

New tests:
- test_extcall.py: 12 tests — star args, kwargs, mixed calls, defaults
- test_iter.py: 25 tests — iter protocol, for loops, enumerate, zip,
  map, filter, reversed, sorted, sum, min/max, any/all, custom iterators
- test_lambda.py: 12 tests — closures, defaults, varargs, callbacks
- test_property.py: 10 tests, 1 skip — property, staticmethod, classmethod
- test_string.py: 21 tests — f-strings, % format, methods, slicing

Total CPython test suites: 34

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
New tests:
- test_bytes.py: 8 tests — literals, indexing, slicing, comparison, decode, methods
- test_builtin.py: 23 tests — abs, bool, chr/ord, divmod, hash, hex/oct/bin,
  id, int, isinstance, len, max/min, pow, range, repr, round, sorted, str,
  sum, type, zip, enumerate, map/filter, callable
- test_types.py: 21 tests, 1 skip — truth values, type checks, conversions
  (int, float, str, bool, list, tuple, set)

Total CPython test suites: 37

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…xtra, test_set_extra, test_list_extra

Infrastructure:
- assertIsNone/assertIsNotNone added to unittest

New tests:
- test_closures.py: 11 tests — closures, nonlocal, nested scopes, lambda closures
- test_dict_extra.py: 20 tests — constructor, get/set/del, keys/values/items,
  get/pop/update/setdefault/clear/copy, comprehension, fromkeys, nested
- test_tuple_extra.py: 18 tests — indexing, slicing, concat, count, index,
  unpacking, star-unpacking, constructor, nested, mixed types
- test_set_extra.py: 20 tests, 1 skip — add/discard/remove/pop/clear,
  union/intersection/difference/symmetric_difference, copy, comprehension,
  frozenset, isdisjoint
- test_list_extra.py: 25 tests — append/extend/insert/remove/pop/index/count,
  reverse/sort/copy/clear, slicing, multiplication, comparison, self-ref repr

Total CPython test suites: 42

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…unpacking, test_inheritance

New tests:
- test_controlflow.py: 23 tests — if/elif/else, while, for, break/continue,
  while/for-else, ternary, pass, nested loops
- test_math_basic.py: 25 tests — int/float/bool arithmetic, bitwise ops,
  abs, divmod, large ints, mixed-type arithmetic
- test_global_nonlocal.py: 12 tests — global/nonlocal statements, enclosing
  scope, class scope, comprehension scope isolation
- test_unpacking.py: 14 tests, 3 skips — tuple/list unpacking, star unpacking,
  nested unpacking, swap, for-loop star unpacking
- test_inheritance.py: 13 tests — single inheritance, super(), method
  resolution, isinstance/issubclass chains, exception inheritance

Total CPython test suites: 47

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ites

Bug fix:
- op_send exhausted: guard gi_return_value read with tp_basicsize > 56.
  Plain iterators (str_iter, list_iter) have smaller objects without
  gi_return_value field. Was crashing on yield-from-string and silently
  returning garbage for some iterator types.
- Export async_gen_asend_type for use by SEND type checks.

New tests (0 skips unless noted):
- test_del.py: 7 tests — del local/list/dict/attribute/multiple
- test_assert.py: 8 tests — assert true/false/message/expression
- test_assignment.py: 28 tests — simple/augmented/subscript/attribute assign
- test_exceptions_extra.py: 17 tests — except clauses, finally, raise/reraise
- test_generators_extra.py: 19 tests — yield, send, yield-from, genexps

Total CPython test suites: 52

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
New tests:
- test_format.py: 24 tests — f-strings (expressions, conversions, adjacent),
  % formatting (string, int, repr, hex, multiple), string methods
- test_slice_ops.py: 14 tests — list/tuple/string slicing, step, negative
  indices, slice assign/delete, extended slicing
- test_numeric.py: 17 tests — int edge cases (large, conversion, bitwise),
  float (special values, NaN, rounding), bool (is-int, arithmetic)
- test_comprehensions.py: 22 tests — list/dict/set comps, genexps with
  filter, nested, closure, empty, max/min/sum/any/all

Total CPython test suites: 56

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…tures

New tests:
- test_decorators_extra.py: 8 tests — function/class/method decorators,
  stacked, with args, staticmethod, classmethod, property
- test_walrus.py: 5 tests — assignment expressions in if/while/listcomp
- test_match.py: 8 tests — match/case with literals, strings, capture,
  or-pattern, guard, tuple pattern, None/True/False patterns
- test_datastructures.py: 14 tests — nested structures, frequency count,
  groupby, sorting with key/reverse, stable sort

Total CPython test suites: 60

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…t_conditional

New tests:
- test_exceptions_builtin.py: 16 tests — exception hierarchy, args, catching,
  error-raising builtins (TypeError, ValueError, IndexError, etc.)
- test_functions.py: 18 tests — defaults, varargs, kwargs, keyword-only,
  recursion (factorial, fibonacci, mutual), higher-order functions
- test_range_extra.py: 13 tests — range constructor, step, negative, len,
  contains, reversed, enumerate, sum
- test_conditional.py: 15 tests — ternary expressions, short-circuit and/or,
  not, chained booleans, is/is not identity

Total CPython test suites: 64

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…es, stdlib modules

Phase 0 — crash/correctness fixes:
- Fix raise segfault on non-exception values (strings, ints)
- Fix callable() false positives for dict/set/list instances
- Fix dict_richcompare r11/r9 clobber bug (5+ entry equality)
- Fix UNPACK_SEQUENCE: raise ValueError on count mismatch

Phase 1 — core language gaps:
- String unpacking: a, b, c = "xyz"
- __ne__ auto-derivation from __eq__ for user classes
- dict() kwargs and iterable support: dict(x=1), dict([(k,v)])
- Set <=, >=, <, > operators (subset/superset)

Phase 2 — 31 new exception types:
GeneratorExit, ModuleNotFoundError, SyntaxError, EOFError,
UnicodeDecodeError/EncodeError, ConnectionError family,
PermissionError, IsADirectoryError, FloatingPointError,
BufferError, SystemError, warning subtypes, and more

Phase 3 — Ellipsis singleton + breakpoint() stub

Phase 4 — pure Python stdlib modules:
abc, operator, string, io (StringIO/BytesIO), contextlib,
copy (copy/deepcopy), collections (Counter, defaultdict,
ChainMap, namedtuple, OrderedDict)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@jgarzik jgarzik self-assigned this Mar 18, 2026
@jgarzik jgarzik merged commit d7d1602 into main Mar 18, 2026
1 check passed
@jgarzik jgarzik deleted the updates branch March 18, 2026 18:20
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