@@ -207,71 +207,76 @@ at exit.
207207.B \- V ", " \-\- version
208208Prints the Python version number of the executable and exits. When given
209209twice, print more information about the build.
210+
210211.TP
211212.BI " \- W " argument
212- Warning control. Python sometimes prints warning message to
213+ Warning control. Python's warning machinery by default prints warning messages
214+ to
213215.IR sys.stderr .
214- A typical warning message has the following form:
215- .IB file " :" line " : " category " : " message.
216- By default, each warning is printed once for each source line where it
217- occurs. This option controls how often warnings are printed.
218- Multiple
219- .B \- W
220- options may be given; when a warning matches more than one
221- option, the action for the last matching option is performed.
222- Invalid
223- .B \- W
224- options are ignored (a warning message is printed about invalid
225- options when the first warning is issued). Warnings can also be
226- controlled from within a Python program using the
227- .I warnings
228- module.
229216
230- The simplest form of
231- .I argument
232- is one of the following
233- .I action
234- strings (or a unique abbreviation):
235- .B ignore
236- to ignore all warnings;
237- .B default
238- to explicitly request the default behavior (printing each warning once
239- per source line);
240- .B all
241- to print a warning each time it occurs (this may generate many
242- messages if a warning is triggered repeatedly for the same source
243- line, such as inside a loop);
244- .B module
245- to print each warning only the first time it occurs in each
246- module;
247- .B once
248- to print each warning only the first time it occurs in the program; or
249- .B error
250- to raise an exception instead of printing a warning message.
217+ The simplest settings apply a particular action unconditionally to all warnings
218+ emitted by a process (even those that are otherwise ignored by default):
251219
252- The full form of
253- .I argument
254- is
255- .IB action : message : category : module : line.
256- Here,
220+ -Wdefault # Warn once per call location
221+ -Werror # Convert to exceptions
222+ -Walways # Warn every time
223+ -Wmodule # Warn once per calling module
224+ -Wonce # Warn once per Python process
225+ -Wignore # Never warn
226+
227+ The action names can be abbreviated as desired and the interpreter will resolve
228+ them to the appropriate action name. For example,
229+ .B -Wi
230+ is the same as
231+ .B -Wignore .
232+
233+ The full form of argument is:
234+ .IB action:message:category:module:lineno
235+
236+ Empty fields match all values; trailing empty fields may be omitted. For
237+ example
238+ .B -W ignore::DeprecationWarning
239+ ignores all DeprecationWarning warnings.
240+
241+ The
257242.I action
258- is as explained above but only applies to messages that match the
259- remaining fields. Empty fields match all values; trailing empty
260- fields may be omitted. The
243+ field is as explained above but only applies to warnings that match
244+ the remaining fields.
245+
246+ The
261247.I message
262- field matches the start of the warning message printed; this match is
263- case-insensitive. The
248+ field must match the whole printed warning message; this match is
249+ case-insensitive.
250+
251+ The
264252.I category
265- field matches the warning category. This must be a class name; the
266- match test whether the actual warning category of the message is a
267- subclass of the specified warning category. The full class name must
268- be given. The
253+ field matches the warning category (ex: "DeprecationWarning"). This must be a
254+ class name; the match test whether the actual warning category of the message
255+ is a subclass of the specified warning category.
256+
257+ The
269258.I module
270- field matches the (fully-qualified) module name; this match is
271- case-sensitive. The
272- .I line
273- field matches the line number, where zero matches all line numbers and
274- is thus equivalent to an omitted line number.
259+ field matches the (fully-qualified) module name; this match is case-sensitive.
260+
261+ The
262+ .I lineno
263+ field matches the line number, where zero matches all line numbers and is thus
264+ equivalent to an omitted line number.
265+
266+ Multiple
267+ .B -W
268+ options can be given; when a warning matches more than one option, the action
269+ for the last matching option is performed. Invalid
270+ .B -W
271+ options are ignored (though, a warning message is printed about invalid options
272+ when the first warning is issued).
273+
274+ Warnings can also be controlled using the
275+ .B PYTHONWARNINGS
276+ environment variable and from within a Python program using the warnings
277+ module. For example, the warnings.filterwarnings() function can be used to use
278+ a regular expression on the warning message.
279+
275280.TP
276281.BI " \- X " option
277282Set implementation specific option. The following options are available:
0 commit comments