Skip to content

Instantly share code, notes, and snippets.

@bbelderbos
Created June 11, 2025 09:57
Show Gist options
  • Save bbelderbos/f667d1f127d1205e416f83dba82c78a3 to your computer and use it in GitHub Desktop.
Save bbelderbos/f667d1f127d1205e416f83dba82c78a3 to your computer and use it in GitHub Desktop.
# /// script
# dependencies = [
# "pydantic",
# ]
# ///
from pydantic import BaseModel
class User(BaseModel):
id: int
name: str
# Confirm slots are present
print("__slots__" in dir(User)) # True
print(hasattr(User, "__slots__")) # True
print(User.__slots__) # ('__fields_set__', '__dict__', '__pydantic_private__', etc.)
# Confirm dynamic attributes are blocked (unlike regular classes)
u = User(id=1, name="Bob")
try:
u.foo = "bar"
except AttributeError as e:
print("No dynamic attributes allowed:", e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment