human
I wrote the below code

    input_factory = factory
    class TheMap(CheckedPMap, ):
        __key_type__ = key_type
        __value_type__ = value_type
    TheMap.__name__ = ((key_type.__name__.capitalize() + value_type.__name__.capitalize()) + 'PMap')
    if optional:
        def mapping_factory(argument):
            if (argument is None):
                return None
            else:
                return TheMap(argument)
    else:
        mapping_factory = TheMap
    if input_factory:
        factory = (lambda x: mapping_factory(input_factory(x)))
    else:
        factory = mapping_factory
    if (initial is _UNDEFINED):
        initial = TheMap()
    else:
        initial = factory(initial)
    return field(mandatory=True, initial=initial, type=(optional_type(TheMap) if optional else TheMap), factory=factory, invariant=invariant)

What's a good function header?
assistant
#Here's a good function header.

def pmap_field(key_type, value_type, optional=False, invariant=_valid, initial=_UNDEFINED, factory=None):