features¶
the basedpython language reference — one page per feature, each with the surface syntax, what it checks, and the python it lowers to
new here?
getting started installs by and walks a .by
file through to running python. this page is the reference you come back to
python compatibility¶
.by is not a superset of .py
- differences from python — every place the same source reads differently
runtime compatibility¶
what the transpiled python does at runtime, beyond what you wrote
- polyfills — write modern python, run it on older interpreters
- runtime type-soundness checks
project-level¶
features that apply to a project rather than to a file
- api lockfile (
api.lock) - declared dependencies — imports checked against
pyproject.toml, and a quick fix that declares them - editor support — postfix templates, completions, inlay hints and the outline
- linting — the
BYrules, and how ruff's own rules read.bysource
standard library¶
what basedpython's vendored typeshed says that upstream's does not
- typeshed improvements — covariant mapping keys, honest
regroups, precisefunctools.cache, and the rest
enhancements that also apply to python¶
type-checking improvements with no new syntax — they work in .by and .py files alike
- fluid specializations
- sound types — infer precise types instead of gradual ones
- precise unsolved type variables — an unsolved type variable is
Never, notUnknown - regex group types — type a match from the pattern it came from
- boolean conditions — catch a test that conflates two members, or asks nothing
- string formatting — check the format spec, and the value that has no rendering of its own
type system¶
what a type is allowed to say
- tuple type literals
- callable arrow syntax
- implicit receivers (
int.() -> str) - intersection types
or/andtype operators- negation types (
not T) - unsafe unions
dynamictypetypeofkeyword- star projections (
X[*]) - strict
floatandcomplex - infinity and nan float literals
- literal type promotion
- use-site type modifiers (
literal T,final T) - symbolic operations in types
- match types
type deftype functions- typed dict literals
- anonymous named tuple types
- inline protocol types
- wrapped optional and result types
- automatic forward references
- implicit typing imports
- typed lambda
- implicit overload stubs
- type narrowing predicates
generics¶
type parameters — their bounds, their variance, and what survives to runtime
- generics
- type mappings
- type parameter bound ranges
- bounds on a variadic pack
- attribute types (
T.a) TypedDictandSelfin type parameters- keyword-variadic packs
- type parameter separators
- typevar variance keywords
- safe variance
- overlapping
- explicit generic call sites
- reified type parameters
- type reification
- parametric type tests
declarations¶
the forms a class, function or binding can take
expressions and statements¶
syntax inside a function body
- context-sensitive resolution —
a: Color = Red - identity and isinstance (
===/!==/is) - optional chaining (
?.) - none-coalesce operator (
??) - postfix await (
.await) castkeyword- checked & safe casts (
cast/cast?) superkeyword- tuple member access (
expr.N) - keyword arguments in subscripts
- destructuring —
let, and patterns in every binding position - destructuring with
if let - statement expressions
- trailing lambda blocks
- unpack syntax
- mutable default arguments
- unique loop bindings — a closure captures its own iteration
- dedented triple-quoted strings
- custom string tags
- strings and characters — grapheme-aware
strapi - repeated
_parameters - lazy imports
- export imports —
from x export y - extensions — add members to an existing type, and declare that it conforms to an existing protocol
- conversions (
__from__/__into__/__of__) - frozen container displays —
{1}for afrozenset - context parameters
- local lifetimes (
local/once) - exception tracking (
raises)
formatting¶
how the formatter lays basedpython out
- assignment alignment — line up the
=of consecutive assignments