How to use the singledispatch.singledispatch function in singledispatch

To help you get started, we’ve selected a few singledispatch examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github travispavek / testrail-python / testrail / helper.py View on Github external
def methdispatch(func):
    dispatcher = singledispatch(func)

    def wrapper(*args, **kw):
        try:
            return dispatcher.dispatch(args[1].__class__)(*args, **kw)
        except IndexError:
            return dispatcher.dispatch(args[0].__class__)(*args, **kw)
    wrapper.register = dispatcher.register
    update_wrapper(wrapper, func)
    return wrapper
github jd-boyd / sexpdata / sexpdata.py View on Github external
@singledispatch
def tosexp(obj, **kwds):
    """
    Convert an object to an S-expression (`dumps` is just calling this).

    See this table for comparison of lispy languages, to support them
    as much as possible:
    `Lisp: Common Lisp, Scheme/Racket, Clojure, Emacs Lisp - Hyperpolyglot
    `_

    Most classes can be supported by tosexp() by adding a __to_lisp_as__ method
    that returns a restructuring of an instance. The method can use builtin
    types, sexpdata hinting classes, and instances of classes that have
    tosexp() support.

    Methods that require customizing the recursion or output string of tosexp()
    should be registered with @sexpdata.tosexp.register(). Also the default
github pydap / pydap / src / pydap / responses / dds.py View on Github external
@singledispatch
def dds(var, level=0, sequence=0):
    """Single dispatcher that generates the DDS response."""
    raise StopIteration
github lanl / scout / compiler / lib / lcomp / imports.py View on Github external
@singledispatch
def augment_node(node, opts):
    raise Exception('Failed to augment imports for %s' % node)
github PyMamba / mamba-framework / mamba / web / routing.py View on Github external
def __init__(self):

        self.routes = {
            'GET': defaultdict(dict),
            'POST': defaultdict(dict),
            'PUT': defaultdict(dict),
            'DELETE': defaultdict(dict),
            'OPTIONS': defaultdict(dict),
            'PATCH': defaultdict(dict),
            'HEAD': defaultdict(dict)
        }

        self._prepare_response = singledispatch(self._prepare_response)
        self._prepare_response.register(str, self._prepare_response_str)
        self._prepare_response.register(
            response.Response, self._prepare_response_object)

        super(Router, self).__init__()
github pydap / pydap / src / pydap / responses / ascii.py View on Github external
@singledispatch
def ascii(var, printname=True):
    """A single dispatcher for the ASCII response."""
    raise StopIteration
github ingolemo / python-lenses / lenses / typeclass.py View on Github external
@singledispatch
def fmap(functor, func):
    # type: (Any, Callable[[Any], Any]) -> Any
    '''Applies a function to the data 'inside' a functor.

    Uses functools.singledispatch so you can write your own functors
    for use with the library.'''
    return functor.map(func)
github lanl / scout / compiler / lib / lcomp / pretty.py View on Github external
@singledispatch
def pretty_print_node(node, cx):
    raise Exception('Pretty printing failed at %s' % node)
github johnbywater / eventsourcing / eventsourcing / domain / model / notificationlog.py View on Github external
@singledispatch
def notification_log_mutator(event, initial):
    return entity_mutator(event, initial)
github PyMamba / mamba-framework / mamba / web / page.py View on Github external
def generate_dispatches(self):
        """Generate singledispatches
        """

        self.add_template_paths = singledispatch(self.add_template_paths)
        self.add_template_paths.register(str, self._add_template_paths_str)
        self.add_template_paths.register(list, self._add_template_paths_list)
        self.add_template_paths.register(tuple, self._add_template_paths_tuple)

singledispatch

Backport functools.singledispatch to older Pythons.

MIT
Latest version published 8 months ago

Package Health Score

75 / 100
Full package analysis