Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions traitlets/traitlets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1399,8 +1399,13 @@ def _register_validator(self, handler, names):

def add_traits(self, **traits):
"""Dynamically add trait attributes to the HasTraits instance."""
self.__class__ = type(self.__class__.__name__, (self.__class__,),
traits)
cls = self.__class__
attrs = {"__module__": cls.__module__}
if hasattr(cls, "__qualname__"):
# __qualname__ introduced in Python 3.3 (see PEP 3155)
attrs["__qualname__"] = cls.__qualname__
attrs.update(traits)
self.__class__ = type(cls.__name__, (cls,), attrs)
for trait in traits.values():
trait.instance_init(self)

Expand Down