Repository navigation
Batch pmp17: feat/tp-s2 up to d47d66ed - #553
Merged
Merged
Conversation
A parameter or result annotated KeysView[K], ValuesView[V] or ItemsView[K, V] (from collections.abc import ..., the one `from` import of an AOT program, for annotations only) holds the view's dict, as a view name does. A KeysView compares only the keys of its dict and a ValuesView only the values (ir.view_match), so a KeysView[str] takes the keys of any dict[str, V]. A call returning a view is used as a view (loop, len, in, truth, repr, binding, passing on); a method returning a view and a view at the library boundary are refused. Agent proposal, not confirmed.
#443) typedpython/comprehensions.py rewrites a comprehension that is the whole value of an assignment to a name or of a return into the loop it means, before the tuples are split: a hidden local per variable (Python 3 scoping), typed by Pyrefly at a probe placed before the statement in the typed copy; a hidden accumulator typed as the target, so the target is bound once the comprehension is complete; CPython's order of evaluation (a dict comprehension's key before its value). Elsewhere a comprehension is refused as "bind it to a name first"; aot-check reports only those as pending. Agent proposal, not confirmed.
A method annotated -> KeysView[K] (ValuesView, ItemsView) compiles: obj.m() on a local of the class is a view call as a module function's is (a local, a for loop, len, in, truth, print, passed to a view parameter, returned as a view); any other use is refused naming the view.
…on clause (#443) for i, x in enumerate(it, start) is the loop over it with a hidden counter bound to i before the body; for a, b in zip(xs, ys) reads names of lists or strs by index while the index is below every length (typedpython/loops.py). zip's names are typed as the elements of the operands Pyrefly types in the for header; a dict or set operand, strict=, a single target name and enumerate or zip anywhere else are refused.
for x in reversed(xs), also inside enumerate() and in a comprehension clause, reads the list or str by index from its end, the index checked against the length at every step as CPython's reversed list iterator checks it (typedpython/loops.py).
r = range(a, b, STEP) with an int constant step is held as its start and stop in hidden int locals and its length computed once per binding (typedpython/ranges.py); a for loop over it, len(), in, its truth and its repr are rewritten into what CPython computes. A non-constant or zero step, a name bound to a range and to anything else, and any other use are refused.
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.
CI run 45945970396 (ci.yml) at f70add3: every job green except the recorded WasmCompiledWheelTest (599 run, 1 failed; wasmJsBrowserTest 10), which waits for pypackpack #82's cp315t wasm wheel (Decision 10 c1). This lands feat/tp-s2 up to d47d66e (S2c: reversed, enumerate, zip and the earlier S2 commits, part of #443). Bench compile-set diff develop d2df489 vs d47d66e: EQUAL.