-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
The static methods section in Module 2 shows how to create factory methods but could better explain when and why to use them.
Current state
The notes mention it's "less cumbersome" to create instances, but the pedagogical value could be stronger.
Suggested improvements
-
Name the pattern - Use the term "factory method" or "alternative constructor" so students can recognize and search for it
-
Explain the "why" - Python doesn't support multiple
__init__signatures, so factory methods provide multiple construction paths with semantic clarity -
Add stdlib examples from datetime:
datetime.fromtimestamp()datetime.fromisoformat()date.fromordinal()
-
Add examples from polars:
pl.read_csv(),pl.read_parquet(),pl.read_json()(module-level factories)DataFrame.to_dict()→pl.from_dict()round-trippl.from_numpy(),pl.from_pandas()
These examples show the pattern is pervasive in well-designed Python APIs.
Metadata
Metadata
Assignees
Labels
No labels