@kernlang/python 4.1.1-canary.226.1.c0be05e9 → 4.1.1-canary.228.1.41c150f2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -40,7 +40,7 @@
40
40
  * threads a `indent` string. The propagation hoist embeds its own 4-space
41
41
  * relative indent on the `return __k_tN` line; the wrapper prepends the
42
42
  * surrounding indent so the post-emit result nests correctly. */
43
- import { applyTemplate, assertNoDecimalOperator, classifyRegexLiteralIndexReadFailClose, classifyRegexLiteralMemberReadFailClose, decimalBareConstructionFailMessage, emitStringKeyArray, expandRegexIFold, instanceofRhsPythonType, instanceofRhsRejectReasonForName, isHostNamespaceRoot, isPostfixMutationOperator, isSupportedAssignOperator, isZeroWidthCapableRegex, KERN_DECIMAL_OPS_HELPER_PY, KERN_STDLIB_MODULES, lookupStdlibCall, lookupStdlibProperty, lowerRegexAnchorsPython, lowerRegexNamedGroupsPython, needsArgParens, needsBinaryParens, normalizeRegexClasses, parseExpression, parseKeys, REGEX_EXEC_FAILCLOSE, REGEX_HOST_REGEXP_FAILCLOSE, REGEX_MATCHALL_NO_G_FAILCLOSE, REGEX_NONLITERAL_FAILCLOSE, REGEX_REPLACE_NONLITERAL_REPL_FAILCLOSE, REGEX_REPLACEALL_NO_G_FAILCLOSE, REGEX_SPLIT_LIMIT_FAILCLOSE, REGEX_SPLIT_ZEROWIDTH_FAILCLOSE, REGEX_TEST_G_FAILCLOSE, regexAstralFailMessage, regexCaptureMeta, regexIFoldFailMessage, regexLiteralReceiverIR, regexMethodRegexArgIdent, scanRegexAstral, suggestStdlibMethod, translateReplStringToPython, unmappedHostNamespaceMessage, unwrapTransparentReceiverIR, validateDecimalConstructionArg, validateDecimalDivModArgs, validateDecimalOperands, validateDecimalPowArgs, validateRegexNamedGroupsPortable, } from '@kernlang/core';
43
+ import { applyTemplate, assertNoDecimalOperator, classifyRegexLiteralIndexReadFailClose, classifyRegexLiteralMemberReadFailClose, decimalBareConstructionFailMessage, emitStringKeyArray, expandRegexIFold, instanceofRhsPythonType, instanceofRhsRejectReasonForName, isHostNamespaceRoot, isPostfixMutationOperator, isSupportedAssignOperator, isZeroWidthCapableRegex, KERN_DECIMAL_OPS_HELPER_PY, KERN_STDLIB_MODULES, KERN_TEXT_OPS_HELPER_PY, lookupStdlibCall, lookupStdlibProperty, lowerRegexAnchorsPython, lowerRegexNamedGroupsPython, needsArgParens, needsBinaryParens, normalizeRegexClasses, parseExpression, parseKeys, REGEX_EXEC_FAILCLOSE, REGEX_HOST_REGEXP_FAILCLOSE, REGEX_MATCHALL_NO_G_FAILCLOSE, REGEX_NONLITERAL_FAILCLOSE, REGEX_REPLACE_NONLITERAL_REPL_FAILCLOSE, REGEX_REPLACEALL_NO_G_FAILCLOSE, REGEX_SPLIT_LIMIT_FAILCLOSE, REGEX_SPLIT_ZEROWIDTH_FAILCLOSE, REGEX_TEST_G_FAILCLOSE, regexAstralFailMessage, regexCaptureMeta, regexIFoldFailMessage, regexLiteralReceiverIR, regexMethodRegexArgIdent, scanRegexAstral, suggestStdlibMethod, translateReplStringToPython, unmappedHostNamespaceMessage, unwrapTransparentReceiverIR, validateDecimalConstructionArg, validateDecimalDivModArgs, validateDecimalOperands, validateDecimalPowArgs, validateRegexNamedGroupsPortable, } from '@kernlang/core';
44
44
  // Slice 0.9 — the TypeScript-AST closure helpers + classifier live on the Node
45
45
  // subpath (the barrel is browser-safe). Python codegen is Node-side and parses
46
46
  // block-bodied arrows, so it injects `typescriptClosureClassifier`.
@@ -1930,6 +1930,22 @@ function emitPyExprCtx(node, ctx) {
1930
1930
  if (arg.kind === 'ident' && arg.name === 'Error') {
1931
1931
  return 'Exception()';
1932
1932
  }
1933
+ // Milestone 5.1b — `new Map()` (EMPTY constructor only) → Python `dict()`.
1934
+ // Without this, `new Map()` fell through to the generic `arg` emit path
1935
+ // below and produced a bare, undefined `Map()` call (Python has no
1936
+ // global `Map`) — a real pre-existing gap, closed here because the new
1937
+ // Map.get/has/set stdlib slice needs a working Python-side constructor
1938
+ // to be reachable at all. A non-empty form (`new Map([[k,v],...])`)
1939
+ // still falls through unmapped (unsupported, not this slice's scope).
1940
+ // Honors user shadowing via `isProvenUserBinding`, same as the RegExp
1941
+ // guard just below.
1942
+ if (arg.kind === 'call' &&
1943
+ arg.callee.kind === 'ident' &&
1944
+ arg.callee.name === 'Map' &&
1945
+ arg.args.length === 0 &&
1946
+ !isProvenUserBinding(ctx, 'Map')) {
1947
+ return 'dict()';
1948
+ }
1933
1949
  // Slice 2 — `new RegExp(p)` (with or without parens) fails-close BEFORE the
1934
1950
  // fall-through, with the shared regex message (the TS emitter + IR-validate
1935
1951
  // throw the same string). Without this the Python `new` case falls through
@@ -4032,6 +4048,15 @@ function registerStdlibRequirementPython(requirement, ctx) {
4032
4048
  ctx.imports.add('decimal');
4033
4049
  return;
4034
4050
  }
4051
+ // KERN 4.5.0 item 3 — `Text.length/charAt/slice/indexOf/startsWith` register the
4052
+ // shared code-point-ops helper block (single-sourced in `text-contract.ts`,
4053
+ // mirroring the Decimal `decimal-ops` requirement above). No import needed —
4054
+ // Python's `str` is already code-point-native, so the helpers are pure
4055
+ // bounds/well-formedness guards around native operators.
4056
+ if (requirement === 'text-ops') {
4057
+ ctx.helpers.add(KERN_TEXT_OPS_HELPER_PY);
4058
+ return;
4059
+ }
4035
4060
  ctx.imports.add(requirement);
4036
4061
  }
4037
4062
  function lowerListLambdaPython(moduleName, methodName, call, ctx) {