You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Add "Some documentation points" to `CONTRIBUTING.md`
- Add separate `docs/Writing_Doctests.md` deep-dive document
- Configure Sphinx to include `Writing_Doctests.md` in docs
Exception: if using a generator to create an expression:
66
72
67
-
import keyword
68
-
python_keywords = keyword.kwlist
69
-
any_keyword = pp.MatchFirst(pp.Keyword(kw)
70
-
for kw in python_keywords))
73
+
```python
74
+
import keyword
75
+
python_keywords = keyword.kwlist
76
+
any_keyword = pp.MatchFirst(pp.Keyword(kw)
77
+
for kw in python_keywords))
78
+
```
71
79
72
-
- Learn [Common Pitfalls When Writing Parsers](https://github.com/pyparsing/pyparsing/wiki/Common-Pitfalls-When-Writing-Parsers) and
80
+
- Learn [Common Pitfalls When Writing Parsers][pitfalls] and
73
81
how to avoid them when developing new examples.
74
82
75
-
- See additional notes under [Some Coding Points](#some-coding-points).
83
+
- See additional notes under [Some coding points](#some-coding-points).
76
84
77
85
## Submitting changes
78
86
@@ -88,11 +96,11 @@ intended on prior versions of Python (currently back to Python 3.6.8).
88
96
89
97
## Some design points
90
98
91
-
- Minimize additions to the module namespace. Over time, pyparsing's namespace has acquired a *lot* of names.
99
+
- Minimize additions to the module namespace. Over time, pyparsing's namespace has acquired a _lot_ of names.
92
100
New features have been encapsulated into namespace classes to try to hold back the name flooding when importing
93
101
pyparsing.
94
102
95
-
- New operator overloads for ParserElement will need to show broad applicability, and should be related to
103
+
- New operator overloads for ParserElement will need to show broad applicability, and should be related to
96
104
parser construction.
97
105
98
106
- Performance tuning should focus on parse time performance. Optimizing parser definition performance is secondary.
@@ -108,28 +116,87 @@ These coding styles are encouraged whether submitting code for core pyparsing or
108
116
name casing. I had just finished several years of Java and Smalltalk development, and camel case seemed to be the
109
117
future trend in coding styles. As of version 3.0.0, pyparsing is moving over to PEP8 naming, while maintaining
110
118
compatibility with existing parser code by defining synonyms using the legacy names. These names will be
111
-
retained until a future release (probably 4.0), to provide a migration path for current pyparsing-dependent
119
+
retained until a future release (probably 4.0), to provide a migration path for current pyparsing-dependent
112
120
applications - DO NOT MODIFY OR REMOVE THESE NAMES.
113
121
See more information at the [PEP8 wiki page](https://github.com/pyparsing/pyparsing/wiki/PEP-8-planning).
114
122
115
123
- No backslashes for line continuations.
116
-
Continuation lines for expressions in ()'s should start with the continuing operator:
124
+
Continuation lines for expressions in `()`'s should start with the continuing operator:
117
125
118
-
really_long_line = (something
119
-
+ some_other_long_thing
120
-
+ even_another_long_thing)
126
+
```python
127
+
really_long_line = (something
128
+
+ some_other_long_thing
129
+
+ even_another_long_thing)
130
+
```
121
131
122
132
- Maximum line length is 120 characters. (Black will override this.)
123
133
124
134
- Changes to core pyparsing must be compatible back to Py3.6 without conditionalizing. Later Py3 features may be
125
135
used in examples by way of illustration.
126
136
127
-
- str.format() statements should use named format arguments (unless this proves to be a slowdown at parse time).
137
+
-`str.format()` statements should use named format arguments (unless this proves to be a slowdown at parse time).
128
138
129
139
- List, tuple, and dict literals should include a trailing comma after the last element, which reduces changeset
130
140
clutter when another element gets added to the end.
131
141
132
-
- New features should be accompanied by updates to unitTests.py and a bullet in the CHANGES file.
142
+
- New features should be accompanied by updates to `unitTests.py` and a bullet in the CHANGES file.
133
143
134
-
- Do not modify pyparsing_archive.py. This file is kept as a reference artifact from when pyparsing was distributed
144
+
- Do not modify `pyparsing_archive.py`. This file is kept as a reference artifact from when pyparsing was distributed
135
145
as a single source file.
146
+
147
+
## Some documentation points
148
+
149
+
- The docstrings in pyparsing (which are generated into the package's
150
+
API documentation by Sphinx) make heavy use of doctests for their
151
+
example code. This allows examples to be tested and verified as
152
+
working, and ensures that any changes to the code which affect
153
+
output are accompanied by corresponding changes in the examples.
154
+
155
+
- The codebase's docstring tests can be verified by running the
156
+
command `make doctest` from the `docs/` directory. The output
157
+
should ideally look something like this:
158
+
159
+
```console
160
+
$ make doctest
161
+
[...documentation build...]
162
+
running tests...
163
+
164
+
Document: pyparsing
165
+
-------------------
166
+
1 item passed all tests:
167
+
204 tests in default
168
+
204 tests in 1 item.
169
+
204 passed.
170
+
Test passed.
171
+
172
+
Document: whats_new_in_3_1
173
+
--------------------------
174
+
1 item passed all tests:
175
+
15 tests in default
176
+
15 tests in 1 item.
177
+
15 passed.
178
+
Test passed.
179
+
180
+
Doctest summary
181
+
===============
182
+
219 tests
183
+
0 failures in tests
184
+
0 failures in setup code
185
+
0 failures in cleanup code
186
+
```
187
+
188
+
Any failed tests will be displayed in detail.
189
+
190
+
- Much more information about doctests can be found in the
191
+
[Pyparsing documentation][pyparsing-docs], in the chapter titled
192
+
"Writing doctest examples". Even if you have never worked with them
193
+
before, it should guide you through everything you need to know in
194
+
order to write Pyparsing doctest examples. If you are already familiar
195
+
with doctests and with `sphinx.ext.doctest` in general, you may wish
196
+
to skip over the introductory content and go straight to the section
197
+
on "Doctests in Pyparsing" which covers some issues specific to the
198
+
project.
199
+
200
+
<!-- Named hyperlink targets, used in the preceding text -->
0 commit comments