# Buggy code
def __new__(meta_cls, class_name, bases, class_dict):
    """ """
    names_with_refs = set()
    container_names = set()

    # Now handle all the Override
    overridden_defaults = {}
    for name, prop in class_dict.items():
        if not isinstance(prop, Override):
            continue
        if prop.default_overridden:
            overridden_defaults[name] = prop.default

    for name, default in overridden_defaults.items():
        del class_dict[name]

    generators = dict()
    for name, generator in class_dict.items():
        if isinstance(generator, PropertyDescriptorFactory):
            generators[name] = generator
        elif isinstance(generator, type) and issubclass(
            generator, PropertyDescriptorFactory
        ):
            # Support the user adding a property without using parens,
            # i.e. using just the Property subclass instead of an
            # instance of the subclass
            generators[name] = generator.autocreate()

    dataspecs = {}
    new_class_attrs = {}

    for name, generator in generators.items():
        prop_descriptors = generator.make_descriptors(name)
        replaced_self = False
        for prop_descriptor in prop_descriptors:
            if prop_descriptor.name in generators:
                if generators[prop_descriptor.name] is generator:
                    # a generator can replace itself, this is the
                    # standard case like `foo = Int()`
                    replaced_self = True
                    prop_descriptor.add_prop_descriptor_to_class(
                        class_name,
                        new_class_attrs,
                        names_with_refs,
                        container_names,
                        dataspecs,
                    )
                else:
                    # if a generator tries to overwrite another
                    # generator that's been explicitly provided,
                    # use the prop that was manually provided
                    # and ignore this one.
                    pass
            else:
                prop_descriptor.add_prop_descriptor_to_class(
                    class_name,
                    new_class_attrs,
                    names_with_refs,
                    container_names,
                    dataspecs,
                )
        # if we won't overwrite ourselves anyway, delete the generator
        if not replaced_self:
            del class_dict[name]

    class_dict.update(new_class_attrs)

    class_dict["__properties__"] = set(new_class_attrs)
    class_dict["__properties_with_refs__"] = names_with_refs
    class_dict["__container_props__"] = container_names
    if len(overridden_defaults) > 0:
        class_dict["__overridden_defaults__"] = overridden_defaults
    if dataspecs:
        class_dict["__dataspecs__"] = dataspecs

    if "__example__" in class_dict:
        path = class_dict["__example__"]
        class_dict["__doc__"] += _EXAMPLE_TEMPLATE % dict(path=path)

    return super(MetaHasProps, meta_cls).__new__(
        meta_cls, class_name, bases, class_dict
    )


# Traceback (TypeError)
2017-04-18 16:51:23 ERROR    Error on request:
Traceback (most recent call last):
File "/data/projects/python/server-monitoring/env/lib/python2.7/site-packages/werkzeug/serving.py", line 193, in run_wsgi
execute(self.server.app)
File "/data/projects/python/server-monitoring/env/lib/python2.7/site-packages/werkzeug/serving.py", line 181, in execute
application_iter = app(environ, start_response)
File "/data/projects/python/server-monitoring/env/lib/python2.7/site-packages/werkzeug/wsgi.py", line 599, in __call__
return self.app(environ, start_response)
File "/data/projects/python/server-monitoring/env/lib/python2.7/site-packages/werkzeug/contrib/lint.py", line 337, in __call__
app_iter = self.app(environ, checking_start_response)
File "/data/projects/python/server-monitoring/serverMonitoring/Main.py", line 40, in __call__
response, endpoint = self.dispatch_request(request)
File "/data/projects/python/server-monitoring/serverMonitoring/Main.py", line 31, in dispatch_request
func = getattr(importlib.import_module(module[0]), module[1])
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/data/projects/python/server-monitoring/serverMonitoring/Handler/Delivery.py", line 20, in <module>
from serverMonitoring.Handler.Dashboard.Widgets import ChartParameters, Chart
File "/data/projects/python/server-monitoring/serverMonitoring/Handler/Dashboard/Widgets.py", line 20, in <module>
from bokeh.embed import file_html
File "/data/projects/python/server-monitoring/env/lib/python2.7/site-packages/bokeh/embed.py", line 28, in <module>
from .core.json_encoder import serialize_json
File "/data/projects/python/server-monitoring/env/lib/python2.7/site-packages/bokeh/core/json_encoder.py", line 47, in <module>
from ..util.serialization import transform_series, transform_array
File "/data/projects/python/server-monitoring/env/lib/python2.7/site-packages/bokeh/util/serialization.py", line 39, in <module>
__doc__ = __doc__ % ("\n".join("* ``np." + str(x) + "``" for x in BINARY_ARRAY_TYPES))
TypeError: unsupported operand type(s) for %: 'NoneType' and 'str'

# Fixed code
def __new__(meta_cls, class_name, bases, class_dict):
    """ """
    names_with_refs = set()
    container_names = set()

    # Now handle all the Override
    overridden_defaults = {}
    for name, prop in class_dict.items():
        if not isinstance(prop, Override):
            continue
        if prop.default_overridden:
            overridden_defaults[name] = prop.default

    for name, default in overridden_defaults.items():
        del class_dict[name]

    generators = dict()
    for name, generator in class_dict.items():
        if isinstance(generator, PropertyDescriptorFactory):
            generators[name] = generator
        elif isinstance(generator, type) and issubclass(
            generator, PropertyDescriptorFactory
        ):
            # Support the user adding a property without using parens,
            # i.e. using just the Property subclass instead of an
            # instance of the subclass
            generators[name] = generator.autocreate()

    dataspecs = {}
    new_class_attrs = {}

    for name, generator in generators.items():
        prop_descriptors = generator.make_descriptors(name)
        replaced_self = False
        for prop_descriptor in prop_descriptors:
            if prop_descriptor.name in generators:
                if generators[prop_descriptor.name] is generator:
                    # a generator can replace itself, this is the
                    # standard case like `foo = Int()`
                    replaced_self = True
                    prop_descriptor.add_prop_descriptor_to_class(
                        class_name,
                        new_class_attrs,
                        names_with_refs,
                        container_names,
                        dataspecs,
                    )
                else:
                    # if a generator tries to overwrite another
                    # generator that's been explicitly provided,
                    # use the prop that was manually provided
                    # and ignore this one.
                    pass
            else:
                prop_descriptor.add_prop_descriptor_to_class(
                    class_name,
                    new_class_attrs,
                    names_with_refs,
                    container_names,
                    dataspecs,
                )
        # if we won't overwrite ourselves anyway, delete the generator
        if not replaced_self:
            del class_dict[name]

    class_dict.update(new_class_attrs)

    class_dict["__properties__"] = set(new_class_attrs)
    class_dict["__properties_with_refs__"] = names_with_refs
    class_dict["__container_props__"] = container_names
    if len(overridden_defaults) > 0:
        class_dict["__overridden_defaults__"] = overridden_defaults
    if dataspecs:
        class_dict["__dataspecs__"] = dataspecs

    if "__example__" in class_dict:
        path = class_dict["__example__"]

        # running python with -OO will discard docstrings -> __doc__ is None
        if "__doc__" in class_dict and class_dict["__doc__"] is not None:
            class_dict["__doc__"] += _EXAMPLE_TEMPLATE % dict(path=path)

    return super(MetaHasProps, meta_cls).__new__(
        meta_cls, class_name, bases, class_dict
    )