Skip to content

Commit 7643da6

Browse files
committed
group representation fixes
1 parent c0c6354 commit 7643da6

File tree

5 files changed

+12
-14
lines changed

5 files changed

+12
-14
lines changed

doc/source/7_inheritance.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Inheritance and composition
1515

1616
A key feature of abstractions is :term:`composability <composition>`: the
1717
ability to make a complex object or operation out of several components. We can
18-
compose objects by simply making one object a :term:`attribute` of another
18+
compose objects by simply making one object an :term:`attribute` of another
1919
object. This combines objects in a *has a* relationship. For example the
2020
:class:`~example_code.polynomial.Polynomial` class introduced in
2121
:numref:`Chapter %s <objects>` *has a* :class:`tuple` of coefficients. Object
@@ -223,7 +223,7 @@ minimal characterisation of a group will suffice.
223223
224224
def __repr__(self):
225225
"""Return the canonical string representation of the group."""
226-
return f"{type(self).__name__}({repr(self.order)})"
226+
return f"{type(self).__name__}({self.order!r})"
227227
228228
:numref:`cyclic_group` shows an implementation of our minimal conception of
229229
cyclic groups. Before considering it in any detail let's try it out to observe
@@ -239,7 +239,7 @@ the concrete effects of the classes:
239239
2_C5
240240
241241
We observe that we are able to create the cyclic group of order 5. Due to the
242-
definition of the :meth:`~object.__call__` :term:`special method` at line 35,
242+
definition of the :meth:`~object.__call__` :term:`special method` at line 49,
243243
we are then able to create elements of the group by calling the group object.
244244
The group operation then has the expected effect:
245245

@@ -286,7 +286,7 @@ integer between 0 and 5, an exception is raised.
286286
:numref:`cyclic_group` illustrates :term:`composition`: on line 13
287287
:class:`~example_code.groups_basic.Element` is associated with a group object.
288288
This is a classic *has a* relationship: an element has a group. We might have
289-
attempted to construct this the other way around with classes having elements,
289+
attempted to construct this the other way around with groups having elements,
290290
however this would have immediately hit the issue that elements have exactly
291291
one group, while a group might have an unlimited number of elements. Object
292292
composition is typically most successful when the relationship is uniquely
@@ -356,7 +356,7 @@ follows:
356356
357357
def __repr__(self):
358358
"""Return the canonical string representation of the group."""
359-
return f"{type(self).__name__}({repr(self.degree)})"
359+
return f"{type(self).__name__}({self.degree!r})"
360360
361361
We won't illustrate the operation of this class, though the reader is welcome to
362362
:keyword:`import` the :mod:`example_code.groups_basic` module and experiment.
@@ -409,7 +409,7 @@ does.
409409
410410
def __repr__(self):
411411
"""Return the canonical string representation of the element."""
412-
return f"{type(self).__name__}({repr(self.n)})"
412+
return f"{type(self).__name__}({self.n!r})"
413413
414414
415415
class CyclicGroup(Group):

example_code/groups.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def __str__(self):
6363

6464
def __repr__(self):
6565
"""Return the canonical string representation of the element."""
66-
return f"{type(self).__name__}({repr(self.n)})"
66+
return f"{type(self).__name__}({self.n!r})"
6767

6868

6969
class CyclicGroup(Group):

example_code/groups_abc.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ def __str__(self):
3737

3838
def __repr__(self):
3939
"""Return the canonical string representation of the element."""
40-
return f"{type(self).__name__}" \
41-
f"({repr(self.group), repr(self.value)})"
40+
return f"{type(self).__name__}{self.group, self.value!r}"
4241

4342

4443
class Group(ABC):
@@ -82,7 +81,7 @@ def __str__(self):
8281

8382
def __repr__(self):
8483
"""Return the canonical string representation of the element."""
85-
return f"{type(self).__name__}({repr(self.n)})"
84+
return f"{type(self).__name__}({self.n!r})"
8685

8786

8887
class CyclicGroup(Group):

example_code/groups_basic.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def __str__(self):
3030

3131
def __repr__(self):
3232
"""Return the canonical string representation of the element."""
33-
return f"{type(self).__name__}({repr(self.group), repr(self.value)})"
33+
return f"{type(self).__name__}{self.group, self.value!r}"
3434

3535

3636
class CyclicGroup:
@@ -61,7 +61,7 @@ def __str__(self):
6161

6262
def __repr__(self):
6363
"""Return the canonical string representation of the group."""
64-
return f"{type(self).__name__}({repr(self.order)})"
64+
return f"{type(self).__name__}({self.order!r})"
6565

6666

6767
class GeneralLinearGroup:
@@ -95,4 +95,4 @@ def __str__(self):
9595

9696
def __repr__(self):
9797
"""Return the canonical string representation of the group."""
98-
return f"{type(self).__name__}({repr(self.degree)})"
98+
return f"{type(self).__name__}({self.degree!r})"

example_code/polynomial.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from numbers import Number
22

33

4-
54
class Polynomial:
65

76
def __init__(self, coefs):

0 commit comments

Comments
 (0)