As I can see from code public_factory() returns a function that instantiate 
a given class. I can not understand why this can be useful. Why we can't 
just instantiate class directly as Mapper(...)? Could you please, explain. 
This is need for preparation of pull request for Spyne (which integrates 
with SQLAlchemy, but does not support custom mappers).

mapper = public_factory(Mapper, ".orm.mapper")

def public_factory(target, location):
    """Produce a wrapping function for the given cls or classmethod.

    Rationale here is so that the __init__ method of the
    class can serve as documentation for the function.

    """
    if isinstance(target, type):
        fn = target.__init__
        callable_ = target
        doc = "Construct a new :class:`.%s` object. \n\n"\
            "This constructor is mirrored as a public API function; see 
:func:`~%s` "\
            "for a full usage and argument description." % (
                target.__name__, location, )
    else:
        fn = callable_ = target
        doc = "This function is mirrored; see :func:`~%s` "\
            "for a description of arguments." % location

    location_name = location.split(".")[-1]
    spec = compat.inspect_getfullargspec(fn)
    del spec[0][0]
    metadata = format_argspec_plus(spec, grouped=False)
    metadata['name'] = location_name
    code = """\
def %(name)s(%(args)s):
    return cls(%(apply_kw)s)
""" % metadata
    env = {'cls': callable_, 'symbol': symbol}
    exec(code, env)
    decorated = env[location_name]
    decorated.__doc__ = fn.__doc__
    if compat.py2k or hasattr(fn, '__func__'):
        fn.__func__.__doc__ = doc
    else:
        fn.__doc__ = doc
    return decorated

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to