Skip to content

Commit

Permalink
Forward spec down the tree, rather than copy at init time, since it c…
Browse files Browse the repository at this point in the history
…an be set after wrapping
  • Loading branch information
tlbtlbtlb committed Mar 10, 2017
1 parent 7c7d2f8 commit 2a0a2a3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions gym/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ def __new__(cls, *args, **kwargs):
env._closed = False

# Will be automatically set when creating an environment via 'make'
env.spec = None
return env

# Set this in SOME subclasses
Expand Down Expand Up @@ -203,7 +202,10 @@ def __del__(self):
self.close()

def __str__(self):
return '<{} instance>'.format(type(self).__name__)
if self.spec is not None:
return '<{}<{}>>'.format(type(self).__name__, self.spec.id)
else:
return '<{} instance>'.format(type(self).__name__)

def configure(self, *args, **kwargs):
raise error.Error("Env.configure has been removed in gym v0.8.0, released on 2017/03/05. If you need Env.configure, please use gym version 0.7.x from pip, or checkout the `gym:v0.7.4` tag from git.")
Expand Down Expand Up @@ -257,7 +259,6 @@ def __init__(self, env):
self.action_space = self.env.action_space
self.observation_space = self.env.observation_space
self.reward_range = self.env.reward_range
self.spec = self.env.spec
self._ensure_no_double_wrap()

@classmethod
Expand All @@ -267,7 +268,7 @@ def class_name(cls):
def _ensure_no_double_wrap(self):
env = self.env
while True:
if isinstance(env, Wrapper):
if isinstance(env, Wrapper):
if env.class_name() == self.class_name():
raise error.DoubleWrapperError("Attempted to double wrap with Wrapper: {}".format(self.__class__.__name__))
env = env.env
Expand Down Expand Up @@ -299,6 +300,10 @@ def __repr__(self):
def unwrapped(self):
return self.env.unwrapped

@property
def spec(self):
return self.env.spec

class ObservationWrapper(Wrapper):
def _reset(self):
observation = self.env.reset()
Expand Down
2 changes: 1 addition & 1 deletion gym/envs/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def make(self):
env = cls(**self._kwargs)

# Make the enviroment aware of which spec it came from.
env.spec = self
env.unwrapped.spec = self

return env

Expand Down

0 comments on commit 2a0a2a3

Please sign in to comment.