⚠️This implementation may be out of date or contain bugs. Last updated 2025-12-28.
PEP 505 Implementation
PEP 505 - None-aware operators
Explore the semantics from the proposal with this interactive WebAssembly demo.
Write Python code in the editor, run it in your browser, or experiment in the interactive REPL.
The demo is based on PEP 505 and incorporates ideas from the discussion since.
The is not None check for Maybe is performed for every attribute and subscript.
Code Editor
# Demonstrating PEP 505 None-aware operators
from dataclasses import dataclass
@dataclass
class Item:
name: str
price: float
@dataclass
class ShoppingCard:
items: list[Item] | None = None
@dataclass
class Customer:
name: str | None = None
card: ShoppingCard | None = None
discount: float | None = None
alex = Customer(
name="Alex",
card=ShoppingCard(
items=[
Item("Apples", 3.14),
Item("Bananas", 2.72),
]))
sandra = Customer(card=ShoppingCard())
for customer in (alex, sandra):
print(f"Customer: {customer.name?.upper()}")
customer.name ??= "Unknown customer"
print(f"Updated name: {customer.name}")
total = sum(
item.price for item in customer.card?.items ?? ()
)
print(f"Shopping card total: {total}")
first_item = customer.card?.items?[0]
print(f"First item in shopping card: {first_item}")
second_item = maybe customer.card.items[1]
print(f"Second item in shopping card: {second_item}")
print("---")
Terminal Output
Interactive REPL
Note: This is an experimental WebAssembly build of Python.
Some features like networking, subprocesses, and threading are not available.
Please report issues regarding the demo or implementation to
the implementation repository
.
SharedArrayBuffer, which is required for this demo,
is not available in your browser environment. One common cause
of this failure is loading index.html directly in
your browser instead of using server.py as
described in
Tools/wasm/README.md
.
For more details about security requirements for
SharedArrayBuffer, see
this MDN page.