Skip to content

Commit 6208f63

Browse files
authored
Merge pull request #374 from jdeschenes/python-3
Python 3 Compatibility Fixes
2 parents 01bf50e + cdabe5a commit 6208f63

File tree

118 files changed

+948
-706
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+948
-706
lines changed

docs/source/_extensions/refactordoc/base_doc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
#------------------------------------------------------------------------------
99
import re
1010

11-
from definition_items import DefinitionItem
12-
from line_functions import is_empty, get_indent, fix_backspace, NEW_LINE
11+
from .definition_items import DefinitionItem
12+
from .line_functions import is_empty, get_indent, fix_backspace, NEW_LINE
1313

1414

1515
underline_regex = re.compile(r'\s*\S+\s*\Z')

docs/source/_extensions/refactordoc/class_doc.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
# Copyright (c) 2011, Enthought, Inc.
77
# All rights reserved.
88
#------------------------------------------------------------------------------
9-
from base_doc import BaseDoc
10-
from line_functions import get_indent, replace_at, add_indent
11-
from definition_items import (MethodItem, AttributeItem, TableLineItem,
9+
from .base_doc import BaseDoc
10+
from .line_functions import get_indent, replace_at, add_indent
11+
from .definition_items import (MethodItem, AttributeItem, TableLineItem,
1212
max_attribute_length, max_attribute_index,
1313
ListItem)
1414

docs/source/_extensions/refactordoc/definition_items.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import collections
1111
import re
1212

13-
from line_functions import (add_indent, fix_star, trim_indent, NEW_LINE,
13+
from .line_functions import (add_indent, fix_star, trim_indent, NEW_LINE,
1414
fix_trailing_underscore)
1515

1616
header_regex = re.compile(r'\s:\s?')

docs/source/_extensions/refactordoc/function_doc.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
# Copyright (c) 2011, Enthought, Inc.
88
# All rights reserved.
99
#------------------------------------------------------------------------------
10-
from base_doc import BaseDoc
11-
from line_functions import get_indent, add_indent
12-
from definition_items import ArgumentItem, ListItem
10+
from .base_doc import BaseDoc
11+
from .line_functions import get_indent, add_indent
12+
from .definition_items import ArgumentItem, ListItem
1313

1414

1515
class FunctionDoc(BaseDoc):

docs/source/conf.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
#
1313
# All configuration values have a default value; values that are commented out
1414
# serve to show the default value.
15-
16-
import sys
15+
from __future__ import print_function
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'))
@@ -113,8 +114,8 @@ def __name__(self):
113114
(mod_name, DocMock(mocked_name=mod_name)) for mod_name in MOCK_MODULES)
114115

115116
# Report on what was mocked.
116-
print 'mocking modules {0} and types {1}'.format(
117-
MOCK_MODULES, [mocked[1] for mocked in MOCK_TYPES])
117+
print('mocking modules {0} and types {1}'.format(
118+
MOCK_MODULES, [mocked[1] for mocked in MOCK_TYPES]))
118119

119120
mock_modules()
120121

@@ -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-
execfile(os.path.join('..', '..', 'traits', '__init__.py'), 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:

docs/source/traits_user_manual/advanced.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ specifying only the wildcard character for the attribute name::
177177
File "all_wildcard.py", line 33, in <module>
178178
bill.age = 'middle age'
179179
File "c:\wrk\src\lib\enthought\traits\\trait_handlers.py", line 163, in error
180-
raise TraitError, ( object, name, self.info(), value )
180+
raise TraitError( object, name, self.info(), value )
181181
TraitError: The 'age' trait of a Person instance must be an integer, but a value
182182
of 'middle age' <type 'str'> was specified.
183183
"""
@@ -915,9 +915,9 @@ interface and be open to extensions by adaptation as follows:
915915
# about adaptation.
916916
lines = printable.get_formatted_text(n_cols=20)
917917

918-
print '-- Start document --'
919-
print '\n'.join(lines)
920-
print '-- End of document -\n'
918+
print('-- Start document --')
919+
print('\n'.join(lines))
920+
print('-- End of document -\n')
921921

922922
class TextDocument(HasTraits):
923923
""" A text document. """

docs/source/traits_user_manual/custom.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -366,16 +366,16 @@ value in the dictionary corresponding to the value assigned. For example::
366366

367367
>>> import mapped
368368
>>> my_shape1 = mapped.GraphicShape()
369-
>>> print my_shape1.line_color, my_shape1.fill_color
369+
>>> print(my_shape1.line_color, my_shape1.fill_color)
370370
black red
371-
>>> print my_shape1.line_color_, my_shape1.fill_color_
371+
>>> print(my_shape1.line_color_, my_shape1.fill_color_)
372372
(0.0, 0.0, 0.0, 1.0) (1.0, 0.0, 0.0, 1.0)
373373
>>> my_shape2 = mapped.GraphicShape()
374374
>>> my_shape2.line_color = 'blue'
375375
>>> my_shape2.fill_color = 'green'
376-
>>> print my_shape2.line_color, my_shape2.fill_color
376+
>>> print(my_shape2.line_color, my_shape2.fill_color)
377377
blue green
378-
>>> print my_shape2.line_color_, my_shape2.fill_color_
378+
>>> print(my_shape2.line_color_, my_shape2.fill_color_)
379379
(0.0, 0.0, 1.0, 1.0) (0.0, 1.0, 0.0, 1.0)
380380

381381
This example shows how a mapped trait can be used to create a user-friendly
@@ -449,10 +449,10 @@ For example::
449449
...
450450
>>> alf = Alien()
451451
>>> alf.heads = 'o'
452-
>>> print alf.heads
452+
>>> print(alf.heads)
453453
one
454454
>>> alf.heads = 'tw'
455-
>>> print alf.heads
455+
>>> print(alf.heads)
456456
two
457457
>>> alf.heads = 't' # Error, not a unique prefix
458458
Traceback (most recent call last):
@@ -557,7 +557,7 @@ than a complete sentence::
557557
File "test.py", line 25, in ?
558558
odd_stuff.very_odd = 0
559559
File "C:\wrk\src\lib\enthought\traits\traits.py", line 1119, in validate
560-
raise TraitError, excp
560+
raise TraitError(excp)
561561
traits.traits.TraitError: The 'very_odd' trait of an AnOddClass instance
562562
must be **a positive odd integer** or -10 <= an integer <= -1, but a value
563563
of 0 <type 'int'> was specified.

docs/source/traits_user_manual/deferring.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,17 @@ DelegatesTo object. Consider the following example::
7878
>>> tony = Parent(first_name='Anthony', last_name='Jones')
7979
>>> alice = Parent(first_name='Alice', last_name='Smith')
8080
>>> sally = Child( first_name='Sally', father=tony, mother=alice)
81-
>>> print sally.last_name
81+
>>> print(sally.last_name)
8282
Jones
8383
>>> sally.last_name = 'Cooper' # Updates delegatee
84-
>>> print tony.last_name
84+
>>> print(tony.last_name)
8585
Cooper
8686
>>> sally.last_name = sally.mother # ERR: string expected
8787
Traceback (most recent call last):
8888
File "<stdin>", line 1, in ?
8989
File "c:\src\trunk\enthought\traits\trait_handlers.py", line
9090
163, in error
91-
raise TraitError, ( object, name, self.info(), value )
91+
raise TraitError( object, name, self.info(), value )
9292
traits.trait_errors.TraitError: The 'last_name' trait of a
9393
Parent instance must be a string, but a value of <__main__.Parent object at
9494
0x014D6D80> <class '__main__.Parent'> was specified.
@@ -178,7 +178,7 @@ PrototypedFrom::
178178
>>> maria = Parent(first_name = 'Maria', family_name = 'Gonzalez',\
179179
... favorite_first_name = 'Tomas', child_allowance = 10.0 )
180180
>>> nino = Child( father=fred, mother=maria )
181-
>>> print '%s %s gets $%.2f for allowance' % (nino.first_name, \ ... nino.last_name, nino.allowance)
181+
>>> print('%s %s gets $%.2f for allowance' % (nino.first_name, \ ... nino.last_name, nino.allowance))
182182
Tomas Lopez gets $5.00 for allowance
183183
"""
184184

@@ -236,7 +236,7 @@ example::
236236
last_name = Str
237237

238238
def _last_name_changed(self, new):
239-
print "Parent's last name changed to %s." % new
239+
print("Parent's last name changed to %s." % new)
240240

241241
class Child ( HasTraits ):
242242

@@ -245,7 +245,7 @@ example::
245245
last_name = PrototypedFrom( 'father' )
246246

247247
def _last_name_changed(self, new):
248-
print "Child's last name changed to %s." % new
248+
print("Child's last name changed to %s." % new)
249249

250250
"""
251251
>>> dad = Parent( first_name='William', last_name='Chase' )

docs/source/traits_user_manual/defining.rst

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ casting traits::
225225
traits.trait_errors.TraitError: The 'weight' trait of a Person instance
226226
must be a float, but a value of '180' <type 'str'> was specified.
227227
>>> bill.cweight = '180' # OK, cast to float('180')
228-
>>> print bill.cweight
228+
>>> print(bill.cweight)
229229
180.0
230230
>>>
231231

@@ -536,7 +536,7 @@ it is also a valid value for assignment.
536536
>>> hats = InventoryItem()
537537
>>> hats.name = 'Stetson'
538538

539-
>>> print '%s: %s' % (hats.name, hats.stock)
539+
>>> print('%s: %s' % (hats.name, hats.stock))
540540
Stetson: None
541541

542542
>>> hats.stock = 2 # OK
@@ -742,32 +742,32 @@ the metadata attribute::
742742

743743
t = Test()
744744

745-
print t.trait( 'i' ).default # 99
746-
print t.trait( 'i' ).default_kind # value
747-
print t.trait( 'i' ).inner_traits # ()
748-
print t.trait( 'i' ).is_trait_type( Int ) # True
749-
print t.trait( 'i' ).is_trait_type( Float ) # False
745+
print(t.trait( 'i' ).default) # 99
746+
print(t.trait( 'i' ).default_kind) # value
747+
print(t.trait( 'i' ).inner_traits) # ()
748+
print(t.trait( 'i' ).is_trait_type( Int )) # True
749+
print(t.trait( 'i' ).is_trait_type( Float )) # False
750750

751-
print t.trait( 'lf' ).default # []
752-
print t.trait( 'lf' ).default_kind # list
753-
print t.trait( 'lf' ).inner_traits
751+
print(t.trait( 'lf' ).default) # []
752+
print(t.trait( 'lf' ).default_kind) # list
753+
print(t.trait( 'lf' ).inner_traits)
754754
# (<traits.traits.CTrait object at 0x01B24138>,)
755-
print t.trait( 'lf' ).is_trait_type( List ) # True
756-
print t.trait( 'lf' ).is_trait_type( TraitType ) # True
757-
print t.trait( 'lf' ).is_trait_type( Float ) # False
758-
print t.trait( 'lf' ).inner_traits[0].is_trait_type( Float ) # True
759-
760-
print t.trait( 'foo' ).default # <undefined>
761-
print t.trait( 'foo' ).default_kind # factory
762-
print t.trait( 'foo' ).inner_traits # ()
763-
print t.trait( 'foo' ).is_trait_type( Instance ) # True
764-
print t.trait( 'foo' ).is_trait_type( List ) # False
765-
766-
print t.trait( 'any' ).default # [1, 2, 3]
767-
print t.trait( 'any' ).default_kind # list
768-
print t.trait( 'any' ).inner_traits # ()
769-
print t.trait( 'any' ).is_trait_type( Any ) # True
770-
print t.trait( 'any' ).is_trait_type( List ) # False
755+
print(t.trait( 'lf' ).is_trait_type( List )) # True
756+
print(t.trait( 'lf' ).is_trait_type( TraitType )) # True
757+
print(t.trait( 'lf' ).is_trait_type( Float )) # False
758+
print(t.trait( 'lf' ).inner_traits[0].is_trait_type( Float )) # True
759+
760+
print(t.trait( 'foo' ).default) # <undefined>
761+
print(t.trait( 'foo' ).default_kind) # factory
762+
print(t.trait( 'foo' ).inner_traits) # ()
763+
print(t.trait( 'foo' ).is_trait_type( Instance )) # True
764+
print(t.trait( 'foo' ).is_trait_type( List )) # False
765+
766+
print(t.trait( 'any' ).default) # [1, 2, 3]
767+
print(t.trait( 'any' ).default_kind) # list
768+
print(t.trait( 'any' ).inner_traits) # ()
769+
print(t.trait( 'any' ).is_trait_type( Any )) # True
770+
print(t.trait( 'any' ).is_trait_type( List )) # False
771771

772772
.. rubric:: Footnotes
773773
.. [2] Most callable predefined traits are classes, but a few are functions.

docs/source/traits_user_manual/intro.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ package. These features are elaborated in the rest of this guide.
9191

9292
# NOTIFICATION: This method is called when 'age' changes:
9393
def _age_changed ( self, old, new ):
94-
print 'Age changed from %s to %s ' % ( old, new )
94+
print('Age changed from %s to %s ' % ( old, new ))
9595

9696
# Set up the example:
9797
joe = Parent()
@@ -100,7 +100,7 @@ package. These features are elaborated in the rest of this guide.
100100
moe.father = joe
101101

102102
# DELEGATION in action:
103-
print "Moe's last name is %s " % moe.last_name
103+
print("Moe's last name is %s " % moe.last_name)
104104
# Result:
105105
# Moe's last name is Johnson
106106

0 commit comments

Comments
 (0)