Skip to content

Commit 63c8b83

Browse files
authored
Merge pull request #737 from blink1073/fix-typings
2 parents b931021 + f36686d commit 63c8b83

2 files changed

Lines changed: 18 additions & 13 deletions

File tree

traitlets/tests/test_traitlets.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
link,
5757
observe,
5858
observe_compat,
59+
traitlets,
5960
validate,
6061
)
6162
from traitlets.utils import cast_unicode
@@ -3133,3 +3134,17 @@ def test_object_from_string(s, expected):
31333134
)
31343135
def test_tcp_from_string(s, expected):
31353136
_from_string_test(TCPAddress, s, expected)
3137+
3138+
3139+
def test_all_attribute():
3140+
"""Verify all trait types are added to `traitlets.__all__`"""
3141+
names = dir(traitlets)
3142+
for name in names:
3143+
value = getattr(traitlets, name)
3144+
if not name.startswith("_") and isinstance(value, type) and issubclass(value, TraitType):
3145+
if name not in traitlets.__all__:
3146+
raise ValueError(f"{name} not in __all__")
3147+
3148+
for name in traitlets.__all__:
3149+
if name not in names:
3150+
raise ValueError(f"{name} should be removed from __all__")

traitlets/traitlets.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
"CComplex",
7575
"CFloat",
7676
"CInt",
77+
"CLong",
7778
"CRegExp",
7879
"CUnicode",
7980
"Callable",
@@ -95,7 +96,9 @@
9596
"HasTraits",
9697
"Instance",
9798
"Int",
99+
"Integer",
98100
"List",
101+
"Long",
99102
"MetaHasDescriptors",
100103
"MetaHasTraits",
101104
"ObjectName",
@@ -3455,16 +3458,3 @@ def validate(self, obj, value):
34553458
return value
34563459
else:
34573460
self.error(obj, value)
3458-
3459-
3460-
def _add_all():
3461-
"""add all trait types to `__all__`
3462-
3463-
do in a function to avoid iterating through globals while defining local variables
3464-
"""
3465-
for _name, _value in globals().items():
3466-
if not _name.startswith("_") and isinstance(_value, type) and issubclass(_value, TraitType):
3467-
__all__.append(_name)
3468-
3469-
3470-
_add_all()

0 commit comments

Comments
 (0)