Skip to content

Commit

Permalink
Fix inconsistent spacing style in docs (#1728)
Browse files Browse the repository at this point in the history
This PR fixes inconsistent code styling for parentheses, brackets and
braces in reST docs and `.py` file docstrings.

Co-authored-by: Poruri Sai Rahul <rporuri@enthought.com>
  • Loading branch information
mdickinson and Poruri Sai Rahul committed Dec 14, 2022
1 parent 71672a8 commit 67e096a
Show file tree
Hide file tree
Showing 17 changed files with 183 additions and 184 deletions.
30 changes: 15 additions & 15 deletions docs/source/traits_user_manual/advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ specifying only the wildcard character for the attribute name::
# all_wildcard.py --- Example of trait attribute wildcard rules
from traits.api import Any, HasTraits, Int, Str

class Person ( HasTraits ):
class Person(HasTraits):

# Normal, explicitly defined trait:
name = Str
Expand All @@ -194,7 +194,7 @@ specifying only the wildcard character for the attribute name::
File "all_wildcard.py", line 33, in <module>
bill.age = 'middle age'
File "c:\wrk\src\lib\enthought\traits\\trait_handlers.py", line 163, in error
raise TraitError( object, name, self.info(), value )
raise TraitError(object, name, self.info(), value)
TraitError: The 'age' trait of a Person instance must be an integer, but a value
of 'middle age' <type 'str'> was specified.
"""
Expand Down Expand Up @@ -503,11 +503,11 @@ definition. For example::
@provides(IName)
class Person(HasTraits):

first_name = Str( 'John' )
last_name = Str( 'Doe' )
first_name = Str('John')
last_name = Str('Doe')

# Implementation of the 'IName' interface:
def get_name ( self ):
def get_name(self):
''' Returns the name of an object. '''
name = '{first} {last}'
return name.format(name=self.first_name, last=self.last_name)
Expand Down Expand Up @@ -550,7 +550,7 @@ The most common way to use interfaces is with the
>>> class Apartment(HasTraits):
... renter = Instance(IName)
>>> william = Person(first_name='William', last_name='Adams')
>>> apt1 = Apartment( renter=william )
>>> apt1 = Apartment(renter=william)
>>> print 'Renter is: ', apt1.renter.get_name()
Renter is: William Adams

Expand Down Expand Up @@ -698,7 +698,7 @@ The following code example shows a definition of a simple adapter class::
adaptee = Instance(Person)

# Implement the 'IName' interface on behalf of its client:
def get_name ( self ):
def get_name(self):
name = '{first} {last}'.format(first=self.adaptee.first_name,
last=self.adaptee.last_name)
return name
Expand Down Expand Up @@ -742,7 +742,7 @@ This is the example from the previous section, were the adapter is registered::
adaptee = Instance(Person)

# Implement the 'IName' interface on behalf of its client:
def get_name ( self ):
def get_name(self):
name = '{first} {last}'.format(first=self.adaptee.first_name,
last=self.adaptee.last_name)
return name
Expand Down Expand Up @@ -1118,7 +1118,7 @@ Property Factory Function
The Property() function has the following signature:

.. currentmodule:: traits.traits
.. function:: Property( [fget=None, fset=None, fvalidate=None, force=False, handler=None, trait=None, **metadata] )
.. function:: Property([fget=None, fset=None, fvalidate=None, force=False, handler=None, trait=None, **metadata])
:noindex:

All parameters are optional, including the *fget* "getter", *fvalidate*
Expand All @@ -1133,7 +1133,7 @@ that trait's handler supersedes the *handler* argument, if any. Because the
*fget* parameter accepts either a method or a trait, you can define a Property
trait by simply passing another trait. For example::

source = Property( Code )
source = Property(Code)

This line defines a trait whose value is validated by the Code trait, and whose
getter and setter methods are defined elsewhere on the same class.
Expand Down Expand Up @@ -1241,12 +1241,12 @@ For example::
# transient_metadata.py -- Example of using 'transient' metadata
from traits.api import HasTraits, File, Any

class DataBase ( HasTraits ):
class DataBase(HasTraits):
# The name of the data base file:
file_name = File

# The open file handle used to access the data base:
file = Any( transient = True )
file = Any(transient = True)

In this example, the DataBase class's file trait is marked as transient because
it normally contains an open file handle used to access a data base. Since file
Expand Down Expand Up @@ -1290,12 +1290,12 @@ metadata.
However, in cases where this strategy is insufficient, use the following pattern
to override __getstate__() to remove items that should not be persisted::

def __getstate__ ( self ):
def __getstate__(self):
state = super().__getstate__()

for key in [ 'foo', 'bar' ]:
for key in ['foo', 'bar']:
if key in state:
del state[ key ]
del state[key]

return state

Expand Down
24 changes: 12 additions & 12 deletions docs/source/traits_user_manual/custom.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,20 @@ Here's an example of subclassing a predefined trait class::
# trait_subclass.py -- Example of subclassing a trait class
from traits.api import BaseInt

class OddInt ( BaseInt ):
class OddInt(BaseInt):

# Define the default value
default_value = 1

# Describe the trait type
info_text = 'an odd integer'

def validate ( self, object, name, value ):
def validate(self, object, name, value):
value = super().validate(object, name, value)
if (value % 2) == 1:
return value

self.error( object, name, value )
self.error(object, name, value)

The OddInt class defines a trait that must be an odd integer. It derives from
BaseInt, rather than Int, as you might initially expect. BaseInt and Int are
Expand Down Expand Up @@ -101,8 +101,8 @@ performs additional processing after a value has been validated and assigned.

The signatures of these methods are:

.. method:: validate( object, name, value )
.. method:: post_setattr( object, name, value )
.. method:: validate(object, name, value)
.. method:: post_setattr(object, name, value)

The parameters of these methods are:

Expand Down Expand Up @@ -136,8 +136,8 @@ definition it might have for validate() is ignored.

The signatures of these methods are:

.. method:: get( object, name)
.. method:: set( object, name, value)
.. method:: get(object, name)
.. method:: set(object, name, value)

In these signatures, the parameters are:

Expand Down Expand Up @@ -235,7 +235,7 @@ Reference*.
The most general form of the Trait() function is:

.. currentmodule:: traits.traits
.. function:: Trait(default_value, {type | constant_value | dictionary | class | function | trait_handler | trait }+ )
.. function:: Trait(default_value, {type | constant_value | dictionary | class | function | trait_handler | trait}+)
:noindex:

.. index:: compound traits
Expand All @@ -255,11 +255,11 @@ The following is an example of a compound trait with multiple criteria::
# compound.py -- Example of multiple criteria in a trait definition
from traits.api import HasTraits, Trait, Range

class Die ( HasTraits ):
class Die(HasTraits):

# Define a compound trait definition:
value = Trait( 1, Range( 1, 6 ),
'one', 'two', 'three', 'four', 'five', 'six' )
value = Trait(1, Range(1, 6),
'one', 'two', 'three', 'four', 'five', 'six')

The Die class has a **value trait**, which has a default value of 1, and can have
any of the following values:
Expand Down Expand Up @@ -383,7 +383,7 @@ representing red, green, blue, and transparency values::
'violet': (0.31, 0.184, 0.31, 1.0),
'yellow': (1.0, 1.0, 0.0, 1.0),
'white': (1.0, 1.0, 1.0, 1.0),
'transparent': (1.0, 1.0, 1.0, 0.0) } )
'transparent': (1.0, 1.0, 1.0, 0.0)})

red_color = Trait ('red', standard_color)

Expand Down
25 changes: 12 additions & 13 deletions docs/source/traits_user_manual/deferring.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ DelegatesTo object. Consider the following example::
"""
>>> tony = Parent(first_name='Anthony', last_name='Jones')
>>> alice = Parent(first_name='Alice', last_name='Smith')
>>> sally = Child( first_name='Sally', father=tony, mother=alice)
>>> sally = Child(first_name='Sally', father=tony, mother=alice)
>>> print(sally.last_name)
Jones
>>> sally.last_name = 'Cooper' # Updates delegatee
Expand All @@ -88,7 +88,7 @@ DelegatesTo object. Consider the following example::
File "<stdin>", line 1, in ?
File "c:\src\trunk\enthought\traits\trait_handlers.py", line
163, in error
raise TraitError( object, name, self.info(), value )
raise TraitError(object, name, self.info(), value)
traits.trait_errors.TraitError: The 'last_name' trait of a
Parent instance must be a string, but a value of <__main__.Parent object at
0x014D6D80> <class '__main__.Parent'> was specified.
Expand Down Expand Up @@ -173,11 +173,11 @@ PrototypedFrom::
mother = Instance(Parent)

"""
>>> fred = Parent( first_name = 'Fred', family_name = 'Lopez', \
... favorite_first_name = 'Diego', child_allowance = 5.0 )
>>> fred = Parent(first_name = 'Fred', family_name = 'Lopez', \
... favorite_first_name = 'Diego', child_allowance = 5.0)
>>> maria = Parent(first_name = 'Maria', family_name = 'Gonzalez',\
... favorite_first_name = 'Tomas', child_allowance = 10.0 )
>>> nino = Child( father=fred, mother=maria )
... favorite_first_name = 'Tomas', child_allowance = 10.0)
>>> nino = Child(father=fred, mother=maria)
>>> print('%s %s gets $%.2f for allowance' % (nino.first_name, \ ... nino.last_name, nino.allowance))
Tomas Lopez gets $5.00 for allowance
"""
Expand Down Expand Up @@ -230,27 +230,27 @@ example::
from traits.api \
import HasTraits, Instance, PrototypedFrom, Str

class Parent ( HasTraits ):
class Parent(HasTraits):

first_name = Str
last_name = Str

def _last_name_changed(self, new):
print("Parent's last name changed to %s." % new)

class Child ( HasTraits ):
class Child(HasTraits):

father = Instance( Parent )
father = Instance(Parent)
first_name = Str
last_name = PrototypedFrom( 'father' )
last_name = PrototypedFrom('father')

def _last_name_changed(self, new):
print("Child's last name changed to %s." % new)

"""
>>> dad = Parent( first_name='William', last_name='Chase' )
>>> dad = Parent(first_name='William', last_name='Chase')
Parent's last name changed to Chase.
>>> son = Child( first_name='John', father=dad )
>>> son = Child(first_name='John', father=dad)
Child's last name changed to Chase.
>>> dad.last_name='Jones'
Parent's last name changed to Jones.
Expand Down Expand Up @@ -278,4 +278,3 @@ notif
.. [5] Both of these class es inherit from the Delegate class. Explicit use of
Delegate is deprecated, as its name and default behavior (prototyping) are
incongruous.

0 comments on commit 67e096a

Please sign in to comment.