mirror of
https://github.com/Farama-Foundation/Gymnasium.git
synced 2025-08-23 23:12:46 +00:00
* add dtype to Box * remove board_game, debugging, safety, parameter_tuning environments * massive set of breaking changes - remove python logging module - _step, _reset, _seed, _close => non underscored method - remove benchmark and scoring folder * Improve render("human"), now resizable, closable window. * get rid of default step and reset in wrappers, so it doesn’t silently fail for people with underscore methods * CubeCrash unit test environment * followup fixes * MemorizeDigits unit test envrionment * refactored spaces a bit fixed indentation disabled test_env_semantics * fix unit tests * fixes * CubeCrash, MemorizeDigits tested * gym backwards compatibility patch * gym backwards compatibility, followup fixes * changelist, add spaces to main namespaces * undo_logger_setup for backwards compat * remove configuration.py
42 lines
1.4 KiB
Python
42 lines
1.4 KiB
Python
import sys
|
|
|
|
# We keep the actual reraising in different modules, since the
|
|
# reraising code uses syntax mutually exclusive to Python 2/3.
|
|
if sys.version_info[0] < 3:
|
|
from .reraise_impl_py2 import reraise_impl #pylint: disable=E0401
|
|
else:
|
|
from .reraise_impl_py3 import reraise_impl
|
|
|
|
def reraise(prefix=None, suffix=None):
|
|
old_exc_type, old_exc_value, traceback = sys.exc_info()
|
|
if old_exc_value is None:
|
|
old_exc_value = old_exc_type()
|
|
|
|
e = ReraisedException(old_exc_value, prefix, suffix)
|
|
|
|
reraise_impl(e, traceback)
|
|
|
|
# http://stackoverflow.com/a/13653312
|
|
def full_class_name(o):
|
|
module = o.__class__.__module__
|
|
if module is None or module == str.__class__.__module__:
|
|
return o.__class__.__name__
|
|
return module + '.' + o.__class__.__name__
|
|
|
|
class ReraisedException(Exception):
|
|
def __init__(self, old_exc, prefix, suffix):
|
|
self.old_exc = old_exc
|
|
self.prefix = prefix
|
|
self.suffix = suffix
|
|
|
|
def __str__(self):
|
|
klass = self.old_exc.__class__
|
|
|
|
orig = "%s: %s" % (full_class_name(self.old_exc), klass.__str__(self.old_exc))
|
|
prefixpart = suffixpart = ''
|
|
if self.prefix is not None:
|
|
prefixpart = self.prefix + "\n"
|
|
if self.suffix is not None:
|
|
suffixpart = "\n\n" + self.suffix
|
|
return "%sThe original exception was:\n\n%s%s" % (prefixpart, orig, suffixpart)
|