Skip to content

Commit 492b467

Browse files
committed
-
1 parent 2e7d3a3 commit 492b467

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

source_py3/python_toolbox/misc_tools/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
_ascii_variable_pattern, is_legal_ascii_variable_name,
99
is_magic_variable_name, get_actual_type, is_number, identity_function,
1010
do_nothing, OwnNameDiscoveringDescriptor, find_clear_place_on_circle,
11-
general_sum, general_product, is_legal_email_address, is_type
11+
general_sum, general_product, is_legal_email_address, is_type, NonInstatiable
1212
)
1313
from . import name_mangling
1414
from .proxy_property import ProxyProperty

source_py3/python_toolbox/misc_tools/misc_tools.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,3 +267,13 @@ def is_type(thing):
267267
'''Is `thing` a class? Allowing both new-style and old-style classes.'''
268268
return isinstance(thing, type)
269269

270+
271+
class NonInstatiable:
272+
'''
273+
Class that can't be instatiated.
274+
275+
Inherit from this for classes that should never be instantiated, like
276+
constants and settings.
277+
'''
278+
def __new__(self, *args, **kwargs):
279+
raise RuntimeError('This class may not be instatiated.')
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright 2009-2013 Ram Rachum.
2+
# This program is distributed under the MIT license.
3+
4+
from python_toolbox import cute_testing
5+
6+
from python_toolbox.misc_tools import NonInstatiable
7+
8+
9+
def test():
10+
class MyNonInstatiable(NonInstatiable):
11+
pass
12+
13+
with cute_testing.RaiseAssertor(exception_type=RuntimeError):
14+
MyNonInstatiable()

0 commit comments

Comments
 (0)