source: orange/Orange/OrangeCanvas/scheme/utils.py @ 11367:9630e1bb6112

Revision 11367:9630e1bb6112, 936 bytes checked in by Ales Erjavec <ales.erjavec@…>, 14 months ago (diff)

Added rst documentation for scheme package.

Fixing docstrings in the process.

Line 
1"""
2Utility functions.
3
4"""
5
6
7def name_lookup(qualified_name, globals={}):
8    """
9    Return the object referenced by a qualified name (doted name).
10    """
11    module_name, class_name = qualified_name.rsplit(".", 1)
12    module = __import__(module_name, fromlist=[class_name], globals=globals)
13    return getattr(module, class_name)
14
15
16def qualified_name(qualified_object):
17    """
18    Return a qualified name for `qualified_obj` (type or function).
19    """
20    return "%s.%s" % (qualified_object.__module__, qualified_object.__name__)
21
22
23def check_type(obj, type_or_tuple):
24    if not isinstance(obj, type_or_tuple):
25        raise TypeError("Expected %r. Got %r" % (type_or_tuple, type(obj)))
26
27
28def check_subclass(cls, class_or_tuple):
29    if not issubclass(cls, class_or_tuple):
30        raise TypeError("Expected %r. Got %r" % (class_or_tuple, type(cls)))
31
32
33def check_arg(pred, value):
34    if not pred:
35        raise ValueError(value)
Note: See TracBrowser for help on using the repository browser.