@@ -55,7 +55,7 @@ proposed syntax and semantics.
55
55
Overview
56
56
========
57
57
58
- Since patterns are a new syntactical category with their own rules
58
+ Since patterns are a new syntactic category with their own rules
59
59
and special cases, and since they mix input (given values) and output
60
60
(captured variables) in novel ways, they require a bit of getting used
61
61
to. It is the experience of the authors that this happens quickly when
@@ -285,7 +285,7 @@ Syntax and Semantics
285
285
Patterns
286
286
--------
287
287
288
- The **pattern ** is a new syntactical construct, that could be considered a loose
288
+ The **pattern ** is a new syntactic construct, that could be considered a loose
289
289
generalization of assignment targets. The key properties of a pattern are what
290
290
types and shapes of subjects it accepts, what variables it captures and how
291
291
it extracts them from the subject. For example the pattern ``[a, b] `` matches
@@ -371,7 +371,6 @@ this section are there for helping the reader, not as a full specification.
371
371
372
372
We propose that the match operation should be a statement, not an expression.
373
373
Although in
374
-
375
374
many languages it is an expression, being a statement better suits the general
376
375
logic of Python syntax. See `rejected ideas `_ for more discussion.
377
376
The allowed patterns are described in detail below in the `patterns `_
@@ -654,7 +653,7 @@ Simplified syntax::
654
653
655
654
Mapping pattern is a generalization of iterable unpacking to mappings.
656
655
Its syntax is similar to dictionary display but each key and value are
657
- patterns ``"{" (pattern ":" pattern)+ "}" ``. A ``**name `` pattern is also
656
+ patterns ``"{" (pattern ":" pattern)+ "}" ``. A ``**rest `` pattern is also
658
657
allowed, to extract the remaining items. Only literal and constant value
659
658
patterns are allowed in key positions::
660
659
@@ -700,7 +699,7 @@ Simplified syntax::
700
699
A class pattern provides support for destructuring arbitrary objects.
701
700
There are two possible ways of matching on object attributes: by position
702
701
like ``Point(1, 2) ``, and by name like ``Point(x=1, y=2) ``. These
703
- two can be combined, but positional match cannot follow a match by name.
702
+ two can be combined, but a positional match cannot follow a match by name.
704
703
Each item in a class pattern can be an arbitrary pattern. A simple
705
704
example::
706
705
@@ -735,7 +734,7 @@ Combining multiple patterns (OR patterns)
735
734
736
735
Multiple alternative patterns can be combined into one using ``| ``. This means
737
736
the whole pattern matches if at least one alternative matches.
738
- Alternatives are tried from left to right and have short-circuit property,
737
+ Alternatives are tried from left to right and have a short-circuit property,
739
738
subsequent patterns are not tried if one matched. Examples::
740
739
741
740
match something:
@@ -858,7 +857,7 @@ The procedure is as following:
858
857
sub-patterns succeed, the overall class pattern match succeeds.
859
858
860
859
* If there are match-by-position items and the class has a
861
- ``__match_args__ ``, the item at position ``i ``
860
+ ``__match_args__ `` attribute , the item at position ``i ``
862
861
is matched against the value looked up by attribute
863
862
``__match_args__[i] ``. For example, a pattern ``Point2D(5, 8) ``,
864
863
where ``Point2D.__match_args__ == ["x", "y"] ``, is translated
@@ -1146,7 +1145,7 @@ Note about constants
1146
1145
The fact that a capture pattern is always an assignment target may create unwanted
1147
1146
consequences when a user by mistake tries to "match" a value against
1148
1147
a constant instead of using the constant value pattern. As a result, at
1149
- runtime such match will always succeed and moreover override the value of
1148
+ runtime such a match will always succeed and moreover override the value of
1150
1149
the constant. It is important therefore that static type checkers warn about
1151
1150
such situations. For example::
1152
1151
@@ -1224,7 +1223,7 @@ desire to break or deprecate.
1224
1223
The difference between hard and soft keywords is that hard keywords
1225
1224
are *always * reserved words, even in positions where they make no
1226
1225
sense (e.g. ``x = class + 1 ``), while soft keywords only get a special
1227
- meaning in context. Since our parser backtracks, that means that on
1226
+ meaning in context. Since PEP 617 the parser backtracks, that means that on
1228
1227
different attempts to parse a code fragment it could interpret a soft
1229
1228
keyword differently.
1230
1229
@@ -1340,12 +1339,12 @@ in a cleaner and more maintainable architecture. These use cases tend to
1340
1339
be characterized by a number of features:
1341
1340
1342
1341
* Algorithms which cut across traditional lines of data encapsulation. If an
1343
- algorithm is processing heterogenous elements of different types (such as
1342
+ algorithm is processing heterogeneous elements of different types (such as
1344
1343
evaluating or transforming an abstract syntax tree, or doing algebraic
1345
1344
manipulation of mathematical symbols), forcing the user to implement
1346
1345
the algorithm as individual methods on each element type results in
1347
1346
logic that is smeared across the entire codebase instead of being neatly
1348
- localized in once place.
1347
+ localized in one place.
1349
1348
* Program architectures where the set of possible data types is relatively
1350
1349
stable, but there is an ever-expanding set of operations to be performed
1351
1350
on those data types. Doing this in a strict OOP fashion requires constantly
@@ -2112,7 +2111,7 @@ Pattern Utility Library
2112
2111
-----------------------
2113
2112
2114
2113
Both of the previous ideas would be accompanied by a new Python standard
2115
- library module which would contain a rich set of exotic and useful matchers.
2114
+ library module which would contain a rich set of useful matchers.
2116
2115
However, it it not really possible to implement such a library without
2117
2116
adopting one of the extended pattern proposals given in the previous sections,
2118
2117
so this idea is also deferred.
0 commit comments