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
- language injection — a string that says what language is written inside it
- linting — the
BYrules, and how ruff's own rules read.bysource - the project server —
by checkanswered out of the language server's warm state
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
- refutable unpacking — catch
a, b = ...over a value of unknown length - unused return value — catch a call whose answer is thrown away
- 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
- template literal types
- 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
- reified class type parameters
- type reification
- parametric type tests
declarations¶
the forms a class, function or binding can take
- modifiers and visibility
- block scoping
- based enums (
enum class) - sealed classes
- module api enforcement (
implements) - init method shorthand
- properties
- empty declarations
- main function
- build stamps
sentineldeclarations- decorator keyword
- decorated function parameters
- decorating anything
- inherited default values
expressions and statements¶
syntax inside a function body
- context-sensitive resolution —
a: Color = Red - type tests and identity (
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
- flexible keyword argument names —
f(a.b=1, "x-y"=2) - destructuring —
let, and patterns in every binding position - destructuring with
if let - starred wildcards in class patterns —
case A(x, *_, y) - 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 - static resources —
import "data/config.yaml" as config - extensions — add members to an existing type, and declare that it conforms to an existing protocol
- conversions (
__from__/__into__/__of__) — and discarding a callable's return where the site asked forNone - 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