Type Annotations
Every variable and function signature must carry a type annotation. Sifr infers types in some positions, but being explicit is encouraged and required at function boundaries.Union Types
Use the| operator to declare that a value can be one of several types. Union types are first-class in Sifr and appear throughout the standard library — for example, dictionary lookups return T | None instead of raising a KeyError.
A missing dictionary key returns
None instead of raising an exception. The compiler requires you to handle the None case before using the value as an int.Type Narrowing
When you test a union value withisinstance or is None, the compiler narrows the type inside that branch. You can then access type-specific fields and methods without any cast.
elif chains. Each branch receives only the types that were not eliminated by the preceding conditions.
None Safety
int | None, str | None, and similar optional types are the standard way to represent values that might be absent. The compiler prevents you from using an optional value as its inner type without first checking for None.
Equality Narrowing
The compiler narrowsstr and other scalar types through equality checks as well. In an if/elif chain comparing a string variable against literal values, each branch receives a narrowed type that excludes already-matched cases.
Collection Truthiness
You can test a collection for emptiness with a plainif not check. The compiler maps this to an efficient empty check on the collection.
Generics and TypeVar
Sifr supports generic functions and classes throughTypeVar. Declare a type variable and use it in parameter and return type positions to express relationships between types.
Built-in Scalar Types
| Sifr type | Description |
|---|---|
int | 64-bit signed integer |
float | 64-bit IEEE 754 double |
bool | True / False |
str | UTF-8 string |
None | Absence of value |
Primitive types (
int, float, bool) are Copy types. Passing them to a function does not move or borrow them — the compiler copies the value automatically.