Created
June 11, 2025 09:57
-
-
Save bbelderbos/f667d1f127d1205e416f83dba82c78a3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /// 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