Skip to content

Commit a204332

Browse files
authored
[Enums and Fractions Concepts]: Fix Typos & Grammar Issues as outlined in issue 4165. (#4195)
* Fix typos and grammer issues as outlined in issue 4165. * Stray backticks missing. * Applied fixes from code review.
1 parent b1bae5e commit a204332

4 files changed

Lines changed: 56 additions & 32 deletions

File tree

concepts/enums/about.md

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
11
# About
22

3-
In Python, [an enum][enum-docs] is a set of unique names that are bound unique, **constant** values. Enums are defined by inheriting an `Enum` class. Built-in enum types are available in the module `enum` and the class `Enum` can be imported using `from enum import Enum`.
3+
In Python, [an enum][enum-docs] is a set of unique names that are bound unique, **constant** values.
4+
`Enums` are defined by inheriting an `Enum` class.
5+
Built-in enum types are available in the module `enum` and the class `Enum` can be imported using `from enum import Enum`.
6+
47

58
```python
9+
from enum import Enum
10+
611
class Color(Enum):
712
RED = 1
813
GREEN = 2
914
```
1015

11-
Note that the values of the enum members can be any data types such as str, tuple, float, etc.
16+
Note that the values of the `enum` members can be any data types such as `str`, `tuple`, `float`, etc.
1217

1318
```python
1419
class Color(Enum):
1520
RED = 'red'
1621
GREEN = 'green'
1722
```
1823

19-
Enums can also be created via the following [functional API][enum-functional-api].
24+
`Enums` can also be created using [function-call syntax][enum-functional-example].
2025

2126
```python
27+
from enum import Enum
28+
2229
Animal = Enum('Animal', 'ANT BEE CAT DOG')
2330
list(Animal)
2431
#=> [<Animal.ANT: 1>, <Animal.BEE: 2>, <Animal.CAT: 3>, <Animal.DOG: 4>]
@@ -27,7 +34,7 @@ Animal.ANT.value
2734
#=> 1
2835
```
2936

30-
When assigning the same value to two members in an enum, the latter assigned member will be an alias to the formed one. It is not allowed to use the same name for two members of an enum.
37+
When assigning the same value to two members in an `enum`, the latter assigned member will be an alias to the former one. It is not allowed to use the same name for two different members of an `enum`.
3138

3239
```python
3340
class Color(Enum):
@@ -50,12 +57,13 @@ for member in Color:
5057
# __members__.items() helps you to loop through alias as well
5158
for member in Color.__members__.items():
5259
print(member)
53-
#=>('RED', <Color.RED: 1>)
54-
#=>('GREEN', <Color.GREEN: 2>)
55-
#=>('ALIAS_OF_RED', <Color.RED: 1>)
60+
#=> ('RED', <Color.RED: 1>)
61+
#=> ('GREEN', <Color.GREEN: 2>)
62+
#=> ('ALIAS_OF_RED', <Color.RED: 1>)
5663
```
5764

58-
Enum members can be compared using [`is` (_identity operator_)][identity-keyword] or `is not`. The `==` or `!=` (_equality operators_) work likewise.
65+
`Enum` members can be compared using [`is` (_identity operator_)][identity-keyword] or `is not`. The `==` or `!=` (_equality operators_) work likewise:
66+
5967

6068
```python
6169
a = Color.RED
@@ -76,18 +84,18 @@ class Shape(Enum):
7684
OVAL = auto()
7785
```
7886

79-
To disallow aliasing (_preventing duplicate values with different names_), the `@unique` decorator may be used.
87+
To disallow aliasing (_preventing duplicate values with different names_), the [class decorator][class-decorator] [`@enum.unique`][enum-unique-decorator] decorator may be used.
8088

8189
```python
82-
@unique
90+
@enum.unique
8391
class Shape(Enum):
8492
CIRCLE = 1
8593
SQUARE = 2
8694
TRIANGLE = 1
8795
#=> ValueError: duplicate values found in <enum 'Shape'>: TRIANGLE -> CIRCLE
8896
```
8997

90-
To access an enum member for a given value, this notation can be used: `EnumName(value)`.
98+
To access an `enum` member for a given value, this notation can be used: `<EnumName>(<value>)`.
9199

92100
```python
93101
g = Color(2)
@@ -99,15 +107,23 @@ g
99107
#=> <Color.GREEN: 2>
100108
```
101109

102-
A custom [restricted `Enum`][restricted-enums] can be written by subclassing `Enum` with any mix-in or data-type. For example:
110+
A custom [restricted `Enum`][restricted-enums] can be written by subclassing the `Enum` class with any mix-in or data-type.
111+
For example:
112+
103113

104114
```python
105115
class StrEnum(str, Enum):
106116
pass
107117
```
108118

109-
[enum-docs]: https://docs.python.org/3/library/enum.html
110-
[enum-auto-docs]: https://docs.python.org/3/library/enum.html#using-auto
111-
[enum-functional-api]: https://docs.python.org/3/library/enum.html#functional-api
112-
[restricted-enums]: https://docs.python.org/3/library/enum.html#restricted-enum-subclassing
119+
Subclassing `Enum` is only allowed if the `enum` does **not** define any members.
120+
See the [`enum` how-to][enum-docs] and the [`enum` cookbook][cookbook] for more details and explanations.
121+
122+
[class-decorator]: https://docs.python.org/3/reference/compound_stmts.html#class-definitions
123+
[cookbook]: https://docs.python.org/3/howto/enum.html#enum-cookbook
124+
[enum-auto-docs]: https://docs.python.org/3/library/enum.html#enum.auto
125+
[enum-docs]: https://docs.python.org/3/howto/enum.html#enum-basic-tutorial
126+
[enum-functional-example]: https://docs.python.org/3/library/enum.html
113127
[identity-keyword]: https://www.w3schools.com/python/ref_keyword_is.asp
128+
[restricted-enums]: https://docs.python.org/3/howto/enum.html#restricted-enum-subclassing
129+
[enum-unique-decorator]: https://docs.python.org/3/library/enum.html#enum.unique

concepts/enums/introduction.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
# Introduction
22

3-
In Python, [an enum](https://docs.python.org/3/library/enum.html) is a set of names that are bound to unique `literal`, or `constant` values. Enums are defined by inheriting an `Enum` class. Built-in enum types are available in the module `enum` and the class `Enum` can be imported using `from enum import Enum`.
3+
In Python, [an `enum`][enum-docs] is a set of names that are bound to unique `literal`, or `constant` values.
4+
`Enums` are defined by inheriting from or subclassing an `Enum` class.
5+
Built-in `enum` types are available in the module `enum` and the class `Enum` can be imported using `from enum import Enum`.
6+
47

58
```python
9+
from enum import Enum
10+
611
class Color(Enum):
712
RED = 1
813
GREEN = 2
914
```
1015

11-
Note that the values of the enum members can be any data types such as str, tuple, float, etc.
16+
Note that the values of the `enum` members can be any data types such as `str`, `tuple`, `float`, etc.
1217

1318
```python
1419
class Color(Enum):
1520
RED = 'red'
1621
GREEN = 'green'
1722
```
1823

19-
When assigning the same value to two members in an enum, the latter assigned member will be an alias to the formed one. It is not allowed to use the same name for two members of an enum.
24+
When assigning the same value to two members in an `enum`, the latter assigned member will be an alias to the former one. It is not allowed to use the same name for two different members of an `enum`.
2025

2126
```python
2227
class Color(Enum):
@@ -31,7 +36,7 @@ Color.ALIAS_OF_RED.value
3136
#=> 1
3237
```
3338

34-
Iterating through the members of the enum can be done with the standard `for member in` syntax:
39+
Iterating through the members of the `enum` can be done with the standard `for member in` syntax:
3540

3641
```python
3742
for member in Color:
@@ -40,7 +45,7 @@ for member in Color:
4045
#=> (GREEN, 2)
4146
```
4247

43-
Enum members can be compared using [`is` (_identity operator_)](https://www.w3schools.com/python/ref_keyword_is.asp) or `is not`. The `==` or `!=` (_equality_operators_) work likewise.
48+
`Enum` members can be compared using [`is` (_identity operator_)][identity-keyword] or `is not`. The `==` or `!=` (_equality operators_) work likewise:
4449

4550
```python
4651
a = Color.RED
@@ -52,7 +57,7 @@ a == Color.RED
5257
#=> True
5358
```
5459

55-
To access an enum member for a given value, `EnumName(value)` can be used:
60+
To access an `enum` member for a given value, `<EnumName>(<value>)` can be used:
5661

5762
```python
5863
g = Color(2)
@@ -63,3 +68,6 @@ g is Color.GREEN
6368
g
6469
#=> <Color.GREEN: 2>
6570
```
71+
72+
[enum-docs]: https://docs.python.org/3/library/enum.html
73+
[identity-keyword]: https://www.w3schools.com/python/ref_keyword_is.asp

concepts/fractions/about.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
# About
22

3-
The [`Fractions`][fractions] module allows us to create and work with [`rational numbers`][rational]: fractions with an integer numerator divided by an integer denominator.
3+
The [`fractions`][fractions] module allows us to create and work with [`rational numbers`][rational]: fractions with an integer numerator divided by an integer denominator.
44

55
For example, we can store `2/3` as an exact fraction instead of the approximate `float` value `0.6666...`
66

77
## Creating Fractions
88

99

1010
Unlike `int`, `float`, and `complex` numbers, fractions do not have a literal form.
11-
However, the fractions constructor is quite flexible.
11+
However, the fraction constructor is quite flexible.
1212

13-
Most obviously, it can take take two integers.
14-
Common factors are automatically removed, converting the fraction to its "lowest form": the smallest integers that accurately represent the fraction.
13+
Most obviously, it can take two integers.
14+
Common factors are automatically removed, converting the fraction to its "lowest form" (_the smallest integers that accurately represent the fraction_):
1515

1616

1717
```python
@@ -29,7 +29,7 @@ Fraction(2, 3) # automatically simplified
2929
True
3030
```
3131

32-
The fractions constructor can also parse a string representation:
32+
The fraction constructor can also parse a string representation:
3333

3434

3535
```python

concepts/fractions/introduction.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# Introduction
22

3-
The [`Fractions`][fractions] module allows us to create and work with [`rational numbers`][rational]: fractions with an integer numerator divided by an integer denominator.
3+
The [`fractions`][fractions] module allows us to create and work with [`rational numbers`][rational]: fractions with an integer numerator divided by an integer denominator.
44
For example, we can store `2/3` as an exact fraction instead of the approximate `float` value `0.6666...`.
55

66
Unlike `int`, `float`, and `complex` numbers, fractions do not have a literal form.
7-
However, the fractions constructor is quite flexible.
7+
However, the fraction constructor is quite flexible.
88

9-
Most obviously, it can take take two integers as arguments.
10-
Common factors are automatically removed, converting the fraction to its "lowest form": the smallest integers that accurately represent the fraction:
9+
Most obviously, it can take two integers as arguments.
10+
Common factors are automatically removed, converting the fraction to its "lowest form" (_the smallest integers that accurately represent the fraction_):
1111

1212
```python
1313
>>> from fractions import Fraction
@@ -24,7 +24,7 @@ Fraction(2, 3) # automatically simplified
2424
True
2525
```
2626

27-
The fractions constructor can also parse a string representation:
27+
The fraction constructor can also parse a string representation:
2828

2929
```python
3030
>>> f3 = Fraction('2/3')

0 commit comments

Comments
 (0)