Skip to content

Instantly share code, notes, and snippets.

@peterbe
Created April 15, 2011 01:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterbe/920958 to your computer and use it in GitHub Desktop.
Save peterbe/920958 to your computer and use it in GitHub Desktop.
Like an abstract class that requires you subclass certain methods but for settings. Just a thought
class LazyNotImplementedError:
def __init__(self, error_msg):
self.error_msg = error_msg
def __call__(self, *__):
raise NotImplementedError(self.error_msg)
__str__ = __add__ = __call__
# settings.py example
BASE = LazyNotImplementedError("You must set this in your settings_local")
# tests
try:
BASE + "/"
except NotImplementedError:
pass
try:
print BASE
except NotImplementedError:
pass
try:
import os
os.path.join(BASE, '/')
except NotImplementedError:
pass
try:
print unicode(BASE)
except NotImplementedError:
pass
try:
print repr(BASE)
except NotImplementedError:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment