@@ -99,8 +99,75 @@ to mypy build errors". In this case, you will need to mitigate those errors
99
99
before stubtest will run. Despite potential overlap in errors here, stubtest is
100
100
not intended as a substitute for running mypy directly.
101
101
102
+ Allowlist
103
+ *********
104
+
102
105
If you wish to ignore some of stubtest's complaints, stubtest supports a
103
- pretty handy allowlist system.
106
+ pretty handy :option: `--allowlist ` system.
107
+
108
+ Let's say that you have this python module called ``ex ``:
109
+
110
+ .. code-block :: python
111
+
112
+ try :
113
+ import optional_expensive_dep
114
+ except ImportError :
115
+ optional_expensive_dep = None
116
+
117
+ first = 1
118
+ if optional_expensive_dep:
119
+ second = 2
120
+
121
+ Let's say that you can't install ``optional_expensive_dep `` in CI for some reason,
122
+ but you still want to include ``second: int `` in the stub file:
123
+
124
+ .. code-block :: python
125
+
126
+ first: int
127
+ second: int
128
+
129
+ In this case stubtest will correctly complain:
130
+
131
+ .. code-block :: shell
132
+
133
+ error: ex.second is not present at runtime
134
+ Stub: in file /.../ex.pyi:2
135
+ builtins.int
136
+ Runtime:
137
+ MISSING
138
+
139
+ Found 1 error (checked 1 module)
140
+
141
+ To fix this, you can add an ``allowlist `` entry:
142
+
143
+ .. code-block :: ini
144
+
145
+ # Allowlist entries in `allowlist.txt` file:
146
+
147
+ # Does not exist if `optional_expensive_dep` is not installed:
148
+ ex.second
149
+
150
+ And now when running stubtest with ``--allowlist=allowlist.txt ``,
151
+ no errors will be generated anymore.
152
+
153
+ Allowlists also support regular expressions,
154
+ which can be useful to ignore many similar errors at once.
155
+ They can also be useful for suppressing stubtest errors that occur sometimes,
156
+ but not on every CI run. For example, if some CI workers have
157
+ ``optional_expensive_dep `` installed, stubtest might complain with this message
158
+ on those workers if you had the ``ex.second `` allowlist entry:
159
+
160
+ .. code-block :: ini
161
+
162
+ note: unused allowlist entry ex.second
163
+ Found 1 error (checked 1 module)
164
+
165
+ Changing ``ex.second `` to be ``(ex\.second)? `` will make this error optional,
166
+ meaning that stubtest will pass whether or not a CI runner
167
+ has``optional_expensive_dep`` installed.
168
+
169
+ CLI
170
+ ***
104
171
105
172
The rest of this section documents the command line interface of stubtest.
106
173
@@ -119,15 +186,15 @@ The rest of this section documents the command line interface of stubtest.
119
186
.. option :: --allowlist FILE
120
187
121
188
Use file as an allowlist. Can be passed multiple times to combine multiple
122
- allowlists. Allowlists can be created with --generate-allowlist. Allowlists
123
- support regular expressions.
189
+ allowlists. Allowlists can be created with :option: ` --generate-allowlist `.
190
+ Allowlists support regular expressions.
124
191
125
192
The presence of an entry in the allowlist means stubtest will not generate
126
193
any errors for the corresponding definition.
127
194
128
195
.. option :: --generate-allowlist
129
196
130
- Print an allowlist (to stdout) to be used with --allowlist
197
+ Print an allowlist (to stdout) to be used with :option: ` --allowlist `.
131
198
132
199
When introducing stubtest to an existing project, this is an easy way to
133
200
silence all existing errors.
@@ -141,17 +208,17 @@ The rest of this section documents the command line interface of stubtest.
141
208
142
209
Note if an allowlist entry is a regex that matches the empty string,
143
210
stubtest will never consider it unused. For example, to get
144
- `--ignore-unused-allowlist ` behaviour for a single allowlist entry like
211
+ `` --ignore-unused-allowlist ` ` behaviour for a single allowlist entry like
145
212
``foo.bar `` you could add an allowlist entry ``(foo\.bar)? ``.
146
213
This can be useful when an error only occurs on a specific platform.
147
214
148
215
.. option :: --mypy-config-file FILE
149
216
150
- Use specified mypy config file to determine mypy plugins and mypy path
217
+ Use specified mypy config * file * to determine mypy plugins and mypy path
151
218
152
219
.. option :: --custom-typeshed-dir DIR
153
220
154
- Use the custom typeshed in DIR
221
+ Use the custom typeshed in * DIR *
155
222
156
223
.. option :: --check-typeshed
157
224
0 commit comments