Skip to content

Commit 359c38a

Browse files
committed
Various additional fixes and simplifications.
1 parent 91f8b23 commit 359c38a

File tree

17 files changed

+45
-54
lines changed

17 files changed

+45
-54
lines changed

docs/source/_extensions/refactordoc/line_functions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#-----------------------------------------------------------------------------
1010
import re
1111

12+
1213
#-----------------------------------------------------------------------------
1314
# Pre-compiled regexes
1415
#-----------------------------------------------------------------------------

docs/source/conf.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
# All configuration values have a default value; values that are commented out
1414
# serve to show the default value.
1515
from __future__ import print_function
16-
import sys
16+
import io
1717
import os
18+
import sys
1819

1920
# The docset build will use slightly different formatting rules
2021
BUILD_DOCSET = bool(os.environ.get('BUILD_DOCSET'))
@@ -143,9 +144,12 @@ def __name__(self):
143144

144145
# The default replacements for |version| and |release|, also used in various
145146
# other places throughout the built documents.
146-
d = {}
147-
exec(open(os.path.join('..', '..', 'traits', '__init__.py')).read(), d)
148-
version = release = d['__version__']
147+
version_info = {}
148+
traits_init_path = os.path.join('..', '..', 'traits', '__init__.py')
149+
with io.open(traits_init_path, "r", encoding="utf-8") as version_module:
150+
version_code = compile(version_module.read(), "__init__.py", "exec")
151+
exec(version_code, version_info)
152+
version = release = version_info['__version__']
149153

150154
# There are two options for replacing |today|: either, you set today to some
151155
# non-false value, then it is used:

examples/tutorials/tutor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ def run_code(self):
769769
del values[name]
770770

771771
# Execute the current lab code:
772-
exec(module[2:] in values, values)
772+
exec(module[2:], values, values)
773773

774774
# fixme: Hack trying to update the Traits UI view of the dict.
775775
self.values = {}

setup.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,5 @@ def additional_commands():
180180
platforms=["Windows", "Linux", "Mac OS-X", "Unix", "Solaris"],
181181
zip_safe=False,
182182
use_2to3=False,
183-
# traits_listener.ListenerItem has a trait *next* which gets
184-
# wrongly renamed
185183
cmdclass=additional_commands(),
186184
)

traits/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
__requires__ = [
10-
'six'
10+
'six',
1111
]
1212

1313
class NullHandler(logging.Handler):

traits/has_traits.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -790,9 +790,9 @@ def _trait_monitor_index ( cls, handler ):
790790
if type_handler is type( _handler ):
791791
if (((type_handler is MethodType) or
792792
'cython_function_or_method' in str(type_handler)) and \
793-
(six.get_method_self(handler) is not None)):
793+
(handler.__self__ is not None)):
794794
if ((handler.__name__ == _handler.__name__) and
795-
(six.get_method_self(handler) is six.get_method_self(_handler))):
795+
(handler.__self__ is _handler.__self__)):
796796
return i
797797

798798
elif handler == _handler:
@@ -957,7 +957,7 @@ def wrappern(*args):
957957
if arg is not None:
958958
function(arg, *args)
959959
# Return the correct wrapper depending on the arg count
960-
args = six.get_function_code(function).co_argcount-1
960+
args = function.__code__.co_argcount-1
961961
if args == 0:
962962
return wrapper0
963963
elif args == 1:
@@ -1947,7 +1947,7 @@ def _trait_view ( cls, name, view_element, default_name, view_elements,
19471947
result = view_elements.find( name )
19481948
if (result is None) and (handler is not None):
19491949
method = getattr( handler, name, None )
1950-
if six.callable( method ):
1950+
if callable( method ):
19511951
result = method()
19521952

19531953
return result
@@ -1974,7 +1974,7 @@ def _trait_view ( cls, name, view_element, default_name, view_elements,
19741974

19751975
if handler is not None:
19761976
method = getattr( handler, name, None )
1977-
if six.callable( method ):
1977+
if callable( method ):
19781978
result = method()
19791979
if isinstance( result, ViewElement ):
19801980
return result

traits/tests/test_file.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import os.path as osp
1+
import os
22

33
import six
44

@@ -18,8 +18,8 @@ class FastExampleModel(HasTraits):
1818
class FileTestCase(unittest.TestCase):
1919
def test_valid_file(self):
2020
example_model = ExampleModel(file_name=__file__)
21-
example_model.file_name = osp.__file__
22-
example_model.file_name = six.text_type(osp.__file__)
21+
example_model.file_name = os.path.__file__
22+
example_model.file_name = six.text_type(os.path.__file__)
2323

2424
def test_invalid_file(self):
2525
example_model = ExampleModel(file_name=__file__)
@@ -33,7 +33,7 @@ def test_directory(self):
3333
example_model = ExampleModel(file_name=__file__)
3434

3535
def assign_invalid():
36-
example_model.file_name = osp.dirname(__file__)
36+
example_model.file_name = os.path.dirname(__file__)
3737

3838
self.assertRaises(TraitError, assign_invalid)
3939

@@ -48,4 +48,4 @@ def assign_invalid():
4848
def test_fast(self):
4949
example_model = FastExampleModel(file_name=__file__)
5050
example_model.path = '.'
51-
example_model.path = u'.'
51+
example_model.path = u'.'

traits/tests/test_listeners.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import threading
2525
import time
2626

27-
import six.moves as sm
27+
import six
2828

2929
from traits.testing.unittest_tools import unittest
3030

@@ -38,7 +38,7 @@ def captured_stderr():
3838
Return a context manager that directs all stderr output to a string.
3939
4040
"""
41-
new_stderr = sm.cStringIO()
41+
new_stderr = six.StringIO()
4242
original_stderr = sys.stderr
4343
sys.stderr = new_stderr
4444
try:
@@ -185,7 +185,7 @@ def test_listener_thread_safety(self):
185185
t = threading.Thread(target=foo_writer, args=(a, stop_event))
186186
t.start()
187187

188-
for _ in sm.range(100):
188+
for _ in range(100):
189189
a.on_trait_change(a.foo_changed_handler, 'foo')
190190
time.sleep(0.0001) # encourage thread-switch
191191
a.on_trait_change(a.foo_changed_handler, 'foo', remove=True)

traits/tests/test_new_notifiers.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88
notification really occurs on a separate thread.
99
1010
"""
11+
import threading
1112
import time
1213

13-
import six.moves as sm
14-
1514
from traits.api import Float, HasTraits
1615
from traits.testing.unittest_tools import unittest
1716

@@ -27,7 +26,7 @@ def test_notification_on_separate_thread(self):
2726
notifications = []
2827

2928
def on_foo_notifications(obj, name, old, new):
30-
thread_id = sm._thread.get_ident()
29+
thread_id = threading.current_thread().ident
3130
event = (thread_id, obj, name, old, new)
3231
notifications.append(event)
3332

@@ -41,7 +40,7 @@ def on_foo_notifications(obj, name, old, new):
4140
self.assertEqual(len(notifications), 1)
4241
self.assertEqual(notifications[0][1:], (obj, 'foo', 0, 3))
4342

44-
this_thread_id = sm._thread.get_ident()
43+
this_thread_id = threading.current_thread().ident
4544
self.assertNotEqual(this_thread_id, notifications[0][0])
4645

4746

traits/tests/test_trait_change_event_tracer.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
""" Tests for the trait change event tracer. """
22

3-
import six
4-
53
from traits.api import Float, HasTraits, on_trait_change
64
from traits.testing.unittest_tools import unittest
75

0 commit comments

Comments
 (0)