Skip to content

Commit 49843ee

Browse files
charliecloudberryKotlinIsland
authored andcommitted
update documentation and fix code examples for clarity and accuracy
1 parent 0a3a2be commit 49843ee

18 files changed

Lines changed: 103 additions & 80 deletions

crates/by_typeshed_patch/src/patches/container_overlapping.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
//! `Container` is covariant in its element (`out Element`), so a membership test
44
//! consumes that covariant typevar in an input position. basedpython types the
55
//! parameter as `Overlapping[Element]`: a value is accepted iff it is not
6-
//! disjoint from `Element`, so `1 in xs` and `object() in xs` are allowed for an
7-
//! `xs: Container[int]`, while `"a" in xs` is rejected
6+
//! disjoint from `Element`, so for an `xs: Container[int]` both `1 in xs` and
7+
//! `o in xs` (an `o: object`) are allowed, while `"a" in xs` is rejected. a bare
8+
//! `object()` is inferred `final object` — exactly `object`, so disjoint from
9+
//! `int` — and is rejected like any other disjoint operand
810
//!
911
//! `Container.__contains__` is the abstract membership requirement. every other
1012
//! container that already declares `__contains__` keeps its own declaration

crates/ty/src/cli-reference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ transpiled output to stdout:
5050

5151
```sh
5252
by transpile hello.by
53-
echo 'x[(a, b)]' | by transpile
53+
echo 'a = b ?? 1' | by transpile
5454
```
5555

5656
### `--reverse`

crates/ty_python_semantic/src/api_lockfile.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
//! the lockfile is meant to be diffed, not parsed back into types. any
66
//! type-level change in a public symbol surfaces as a line-level diff
77
//!
8-
//! the first line is `#api-lock:v=1` (grammar version). subsequent lines are
9-
//! sorted lexicographically. one record per line:
8+
//! four `#`-prefixed header lines come first: `#api-lock:v=1` (grammar
9+
//! version), `#tool:by=<version>`, `#python:<target>` and `#modules:<count>`.
10+
//! the records follow, sorted lexicographically, one per line:
1011
//!
1112
//! ```text
1213
//! <qualified>:c[<bases>] # class

docs/basedpython/features/api-lock.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ by generate-api-file -o public.lock
2121

2222
## record grammar
2323

24-
each non-header line is one record. fields are colon-separated. the first
25-
line is the format-version header (`#api-lock:v=1`); the remaining lines
26-
are sorted lexicographically
24+
the file opens with four `#`-prefixed header lines: the format version
25+
(`#api-lock:v=1`), the generating `by` version (`#tool:by=0.0.5`), the target
26+
(`#python:3.13`, or `#python:default` when no `--python-version` was given) and
27+
the number of modules walked (`#modules:12`). every line after them is one
28+
record. fields are colon-separated, and the records are sorted lexicographically
2729

2830
```text
2931
<qualified>:c[<bases>] # class

docs/basedpython/features/checked-cast.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def _checked_cast(_v, _t):
2828
)
2929
return _v
3030

31-
def f(a):
31+
def f(a: object):
3232
b = _checked_cast(a, int)
3333
print(b)
3434
```

docs/basedpython/features/float-literals.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,6 @@ surrounding whitespace) — constructs an ordinary `float`
105105

106106
```by
107107
def f(x: str) -> None:
108-
reveal_type(float(x)) # revealed: float
109-
reveal_type(float("1_000.5")) # revealed: float
108+
reveal_type(float(x)) # revealed: final float
109+
reveal_type(float("1_000.5")) # revealed: final float
110110
```

docs/basedpython/features/implementations.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ implementation A for B:
331331
332332

333333
```python
334-
class __by_impl__A__B(_by_Implementation, A): # basedpython: implementation A for B
334+
class _by_impl__A__B(_by_Implementation, A): # basedpython: implementation A for B
335335
__slots__ = ()
336336

337337
def f(self):
@@ -387,16 +387,16 @@ xs: list[A] = [b1, b2]
387387
388388

389389
```python
390-
f(__by_impl__A__B(b))
391-
xs: list[A] = [__by_impl__A__B(b1), __by_impl__A__B(b2)]
390+
f(_by_impl__A__B(b))
391+
xs: list[A] = [_by_impl__A__B(b1), _by_impl__A__B(b2)]
392392
```
393393

394394
when the implementation lives in another module, the lowering emits the precise
395395
import of the witness class, keyed off the checker's resolution — the same
396396
implicit-import treatment extension members get:
397397

398398
```python
399-
from adapters import __by_impl__A__B
399+
from adapters import _by_impl__A__B
400400
```
401401

402402
## round-tripping
@@ -497,7 +497,7 @@ settling separately. adding inherent members is what extensions are for
497497
(`project_db` + `transpile_typed`), beside
498498
`imported_extension_rewrites_call_and_adds_import`: a conversion site
499499
whose witness class lives in another module must wrap the expression *and*
500-
emit `from impl_mod import __by_impl__A__B`, and the anonymous mangled
500+
emit `from impl_mod import _by_impl__A__B`, and the anonymous mangled
501501
name must agree between the two files
502502
- **runtime** — an `implementation_runtime.rs` beside the other `*_runtime.rs`
503503
integration tests, for shared mutation through a witness, `==` / `hash`

docs/basedpython/features/keyword-variadic.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class A[**Kwargs]:
5454
init(**kwargs: **Kwargs)
5555
5656
a = A(x=1, y="s")
57-
reveal_type(a) # A[x=int, y=str]
57+
reveal_type(a) # final A[x=int, y=str]
5858
```
5959

6060
the pack is solved as a whole rather than per-argument, so `A()` gives the empty pack `A[()]`. field

docs/basedpython/features/none-coalesce.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ name = user.display_name ?? "anonymous"
99
transpiles to:
1010

1111
```python
12-
name = user.display_name if user.display_name is not None else "anonymous"
12+
name = __by_t_0__ if (__by_t_0__ := user.display_name) is not None else "anonymous"
1313
```
1414

15+
a compound left operand is bound to a temp by the walrus so it is evaluated
16+
exactly once. a bare name needs no temp and is repeated directly — `a ?? b` is
17+
`a if a is not None else b`
18+
1519
## semantics
1620

1721
`??` tests `is not None` (identity) — not falsiness. an empty string, zero,

docs/basedpython/features/not-type.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
def f(x: not int) -> None: ...
77
88
f("a") # ok
9-
f()1) # error
9+
f(1) # error
1010
```
1111

1212
transpiles to:

0 commit comments

Comments
 (0)