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
12 changes: 8 additions & 4 deletions traitlets/traitlets.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,8 @@ def __new__(mcls, name, bases, classdict):
v.name = k
elif inspect.isclass(v):
if issubclass(v, TraitType):
warn("Traits should be given as instances, not types (for example, `Int()`, not `Int`)", DeprecationWarning, stacklevel=2)
warn("Traits should be given as instances, not types (for example, `Int()`, not `Int`)",
DeprecationWarning, stacklevel=2)
vinst = v()
vinst.name = k
classdict[k] = vinst
Expand Down Expand Up @@ -1542,7 +1543,8 @@ def __init__(self, trait=None, default_value=None, **metadata):

if is_trait(trait):
if isinstance(trait, type):
warn("Traits should be given as instances, not types (for example, `Int()`, not `Int`)", DeprecationWarning)
warn("Traits should be given as instances, not types (for example, `Int()`, not `Int`)",
DeprecationWarning, stacklevel=3)
self._trait = trait() if isinstance(trait, type) else trait
elif trait is not None:
raise TypeError("`trait` must be a Trait or None, got %s" % repr_type(trait))
Expand Down Expand Up @@ -1737,7 +1739,8 @@ def __init__(self, *traits, **metadata):
self._traits = []
for trait in traits:
if isinstance(trait, type):
warn("Traits should be given as instances, not types (for example, `Int()`, not `Int`)", DeprecationWarning, stacklevel=2)
warn("Traits should be given as instances, not types (for example, `Int()`, not `Int`)",
DeprecationWarning, stacklevel=2)
t = trait() if isinstance(trait, type) else trait
self._traits.append(t)

Expand Down Expand Up @@ -1818,7 +1821,8 @@ def __init__(self, trait=None, traits=None, default_value=Undefined,
# Case where a type of TraitType is provided rather than an instance
if is_trait(trait):
if isinstance(trait, type):
warn("Traits should be given as instances, not types (for example, `Int()`, not `Int`)", DeprecationWarning, stacklevel=2)
warn("Traits should be given as instances, not types (for example, `Int()`, not `Int`)",
DeprecationWarning, stacklevel=2)
self._trait = trait() if isinstance(trait, type) else trait
elif trait is not None:
raise TypeError("`trait` must be a Trait or None, got %s" % repr_type(trait))
Expand Down