Table of Contents

Class Warnings

Namespace
Gym.Utils
Assembly
Gym.dll

The part of Python's warnings module that Logger depends on: its default filters, where shown warnings go, and catch_warnings(record=True) for tests. Gymnasium never throws where it only warns, so neither does Gym: a warning is text on the error stream (or a record), never an exception.

public static class Warnings
Inheritance
Warnings
Inherited Members

Remarks

Filters, as Python applies them to Gymnasium's warnings: a UserWarning is shown the first time a given message is issued from a given call site and suppressed after that (Python's default action, keyed on the text, the category and the location); a DeprecationWarning is shown the first time a given message is issued from anywhere (the once filter Gymnasium's logger installs for its modules). So CartPole's "already returned terminated = True" warning appears once per process, not once per episode, exactly as in Python. Reference: gymnasium/logger.py.

Python forgets which warnings it has shown whenever the filters change (_filters_mutated), which leaving a catch_warnings block does; Catch() mirrors that by clearing the registry when a catcher is disposed. All members are thread-safe.

Properties

Output

Where shown warnings are written, one ToString() line each; null restores Error. Assign it to route warnings into a log or a test's buffer, as Python code replaces sys.stderr or warnings.showwarning.

public static TextWriter? Output { get; set; }

Property Value

TextWriter

Methods

Catch()

Starts recording every warning instead of showing it, as Python's with warnings.catch_warnings(record=True): warnings.simplefilter("always") block does. Dispose the result to stop; that also clears the shown-warnings registry, as leaving Python's block does.

public static WarningCatcher Catch()

Returns

WarningCatcher

The catcher; its Records grow while it is the innermost active one.

ResetRegistry()

Forgets which warnings have been shown, so each is shown again once: the effect of any filter change in Python (warnings.resetwarnings(), filterwarnings(...)). Tests use it to observe the first-time behaviour.

public static void ResetRegistry()

Warn(string, WarningCategory, string, int)

Issues a warning the way warnings.warn(message, category) does: recorded by the innermost active Catch() block, otherwise written to Output unless the default filter has already shown it.

public static void Warn(string message, WarningCategory category, string fileName, int lineNumber)

Parameters

message string

The warning text.

category WarningCategory

The warning class.

fileName string

The call site's file, the location Python's stacklevel selects.

lineNumber int

The call site's line.

Exceptions

ArgumentNullException

Thrown when message or fileName is null.