Notes and exercises for learning design patterns
__new__Implement a basic Singleton for application settings.
The object represents runtime configuration for one running application process. Different parts of the application may call AppSettings(), but they should all receive the same object.
__new__ to control object creation__init__ so it does not reset state every timeisOpen exercise1.py.
You are given an AppSettings class and tests. Fill the TODOs so that:
AppSettings() always returns the same object.environment, debug, or features.settings1 = AppSettings(environment="development", debug=False)
settings2 = AppSettings(environment="production", debug=True)
assert settings1 is settings2
assert settings2.environment == "development"
assert settings2.debug is False
The second call should not create or reinitialize a new settings object.
python -m pytest exercise1.py