The following issues were found

gym/envs/mujoco/thrower.py
5 issues
Parameters differ from overridden 'step' method
Error

Line: 13 Column: 5

                      self._ball_hit_location = None
        mujoco_env.MujocoEnv.__init__(self, "thrower.xml", 5)

    def step(self, a):
        ball_xy = self.get_body_com("ball")[:2]
        goal_xy = self.get_body_com("goal")[:2]

        if not self._ball_hit_ground and self.get_body_com("ball")[2] < -0.25:
            self._ball_hit_ground = True

            

Reported by Pylint.

Attribute 'goal' defined outside __init__
Error

Line: 43 Column: 9

                      self._ball_hit_location = None

        qpos = self.init_qpos
        self.goal = np.array(
            [
                self.np_random.uniform(low=-0.3, high=0.3),
                self.np_random.uniform(low=-0.3, high=0.3),
            ]
        )

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import numpy as np
from gym import utils
from gym.envs.mujoco import mujoco_env


class ThrowerEnv(mujoco_env.MujocoEnv, utils.EzPickle):
    def __init__(self):
        utils.EzPickle.__init__(self)
        self._ball_hit_ground = False

            

Reported by Pylint.

Missing class docstring
Error

Line: 6 Column: 1

              from gym.envs.mujoco import mujoco_env


class ThrowerEnv(mujoco_env.MujocoEnv, utils.EzPickle):
    def __init__(self):
        utils.EzPickle.__init__(self)
        self._ball_hit_ground = False
        self._ball_hit_location = None
        mujoco_env.MujocoEnv.__init__(self, "thrower.xml", 5)

            

Reported by Pylint.

Variable name "ob" doesn't conform to snake_case naming style
Error

Line: 30 Column: 9

              
        reward = reward_dist + 0.002 * reward_ctrl
        self.do_simulation(a, self.frame_skip)
        ob = self._get_obs()
        done = False
        return ob, reward, done, dict(reward_dist=reward_dist, reward_ctrl=reward_ctrl)

    def viewer_setup(self):
        self.viewer.cam.trackbodyid = 0

            

Reported by Pylint.

gym/envs/mujoco/walker2d.py
5 issues
Parameters differ from overridden 'step' method
Error

Line: 11 Column: 5

                      mujoco_env.MujocoEnv.__init__(self, "walker2d.xml", 4)
        utils.EzPickle.__init__(self)

    def step(self, a):
        posbefore = self.sim.data.qpos[0]
        self.do_simulation(a, self.frame_skip)
        posafter, height, ang = self.sim.data.qpos[0:3]
        alive_bonus = 1.0
        reward = (posafter - posbefore) / self.dt

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import numpy as np
from gym import utils
from gym.envs.mujoco import mujoco_env


class Walker2dEnv(mujoco_env.MujocoEnv, utils.EzPickle):
    def __init__(self):
        mujoco_env.MujocoEnv.__init__(self, "walker2d.xml", 4)
        utils.EzPickle.__init__(self)

            

Reported by Pylint.

Missing class docstring
Error

Line: 6 Column: 1

              from gym.envs.mujoco import mujoco_env


class Walker2dEnv(mujoco_env.MujocoEnv, utils.EzPickle):
    def __init__(self):
        mujoco_env.MujocoEnv.__init__(self, "walker2d.xml", 4)
        utils.EzPickle.__init__(self)

    def step(self, a):

            

Reported by Pylint.

Simplify chained comparison between the operands
Error

Line: 19 Column: 21

                      reward = (posafter - posbefore) / self.dt
        reward += alive_bonus
        reward -= 1e-3 * np.square(a).sum()
        done = not (height > 0.8 and height < 2.0 and ang > -1.0 and ang < 1.0)
        ob = self._get_obs()
        return ob, reward, done, {}

    def _get_obs(self):
        qpos = self.sim.data.qpos

            

Reported by Pylint.

Variable name "ob" doesn't conform to snake_case naming style
Error

Line: 20 Column: 9

                      reward += alive_bonus
        reward -= 1e-3 * np.square(a).sum()
        done = not (height > 0.8 and height < 2.0 and ang > -1.0 and ang < 1.0)
        ob = self._get_obs()
        return ob, reward, done, {}

    def _get_obs(self):
        qpos = self.sim.data.qpos
        qvel = self.sim.data.qvel

            

Reported by Pylint.

gym/envs/toy_text/nchain.py
5 issues
Method 'render' is abstract in class 'Env' but is not overridden
Error

Line: 6 Column: 1

              from gym.utils import seeding


class NChainEnv(gym.Env):
    """n-Chain environment

    This game presents moves along a linear chain of states, with two actions:
     0) forward, which moves along the chain but returns no reward
     1) backward, which returns to the beginning and has a small reward

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import gym
from gym import spaces
from gym.utils import seeding


class NChainEnv(gym.Env):
    """n-Chain environment

    This game presents moves along a linear chain of states, with two actions:

            

Reported by Pylint.

Too many instance attributes (8/7)
Error

Line: 6 Column: 1

              from gym.utils import seeding


class NChainEnv(gym.Env):
    """n-Chain environment

    This game presents moves along a linear chain of states, with two actions:
     0) forward, which moves along the chain but returns no reward
     1) backward, which returns to the beginning and has a small reward

            

Reported by Pylint.

Attribute name "n" doesn't conform to snake_case naming style
Error

Line: 27 Column: 9

                  """

    def __init__(self, n=5, slip=0.2, small=2, large=10):
        self.n = n
        self.slip = slip  # probability of 'slipping' an action
        self.small = small  # payout for 'backwards' action
        self.large = large  # payout at end of chain for 'forwards' action
        self.state = 0  # Start at beginning of the chain
        self.action_space = spaces.Discrete(2)

            

Reported by Pylint.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 41
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

                      return [seed]

    def step(self, action):
        assert self.action_space.contains(action)
        if self.np_random.rand() < self.slip:
            action = not action  # agent slipped, reverse action taken
        if action:  # 'backwards': go back to the beginning, get small reward
            reward = self.small
            self.state = 0

            

Reported by Bandit.

gym/vector/__init__.py
5 issues
Redefining built-in 'id'
Error

Line: 13 Column: 10

              __all__ = ["AsyncVectorEnv", "SyncVectorEnv", "VectorEnv", "VectorEnvWrapper", "make"]


def make(id, num_envs=1, asynchronous=True, wrappers=None, **kwargs):
    """Create a vectorized environment from multiple copies of an environment,
    from its id

    Parameters
    ----------

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              try:
    from collections.abc import Iterable
except ImportError:
    Iterable = (tuple, list)

from gym.vector.async_vector_env import AsyncVectorEnv
from gym.vector.sync_vector_env import SyncVectorEnv
from gym.vector.vector_env import VectorEnv, VectorEnvWrapper


            

Reported by Pylint.

Argument name "id" doesn't conform to snake_case naming style
Error

Line: 13 Column: 1

              __all__ = ["AsyncVectorEnv", "SyncVectorEnv", "VectorEnv", "VectorEnvWrapper", "make"]


def make(id, num_envs=1, asynchronous=True, wrappers=None, **kwargs):
    """Create a vectorized environment from multiple copies of an environment,
    from its id

    Parameters
    ----------

            

Reported by Pylint.

Import outside toplevel (gym.envs.make)
Error

Line: 49 Column: 5

                         [ 0.03468829,  0.01500225,  0.01230312,  0.01825218]],
          dtype=float32)
    """
    from gym.envs import make as make_

    def _make_env():
        env = make_(id, **kwargs)
        if wrappers is not None:
            if callable(wrappers):

            

Reported by Pylint.

Use a generator instead 'all(callable(w) for w in wrappers)'
Error

Line: 56 Column: 53

                      if wrappers is not None:
            if callable(wrappers):
                env = wrappers(env)
            elif isinstance(wrappers, Iterable) and all(
                [callable(w) for w in wrappers]
            ):
                for wrapper in wrappers:
                    env = wrapper(env)
            else:

            

Reported by Pylint.

gym/wrappers/gray_scale_observation.py
5 issues
Unable to import 'cv2'
Error

Line: 29 Column: 9

                          )

    def observation(self, observation):
        import cv2

        observation = cv2.cvtColor(observation, cv2.COLOR_RGB2GRAY)
        if self.keep_dim:
            observation = np.expand_dims(observation, -1)
        return observation

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import numpy as np
from gym.spaces import Box
from gym import ObservationWrapper


class GrayScaleObservation(ObservationWrapper):
    r"""Convert the image observation from RGB to gray scale."""

    def __init__(self, env, keep_dim=False):

            

Reported by Pylint.

Consider using Python 3 style super() without arguments
Error

Line: 10 Column: 9

                  r"""Convert the image observation from RGB to gray scale."""

    def __init__(self, env, keep_dim=False):
        super(GrayScaleObservation, self).__init__(env)
        self.keep_dim = keep_dim

        assert (
            len(env.observation_space.shape) == 3
            and env.observation_space.shape[-1] == 3

            

Reported by Pylint.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 13
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

                      super(GrayScaleObservation, self).__init__(env)
        self.keep_dim = keep_dim

        assert (
            len(env.observation_space.shape) == 3
            and env.observation_space.shape[-1] == 3
        )

        obs_shape = self.observation_space.shape[:2]

            

Reported by Bandit.

Import outside toplevel (cv2)
Error

Line: 29 Column: 9

                          )

    def observation(self, observation):
        import cv2

        observation = cv2.cvtColor(observation, cv2.COLOR_RGB2GRAY)
        if self.keep_dim:
            observation = np.expand_dims(observation, -1)
        return observation

            

Reported by Pylint.

gym/wrappers/pixel_observation.py
5 issues
Missing module docstring
Error

Line: 1 Column: 1

              import collections
from collections.abc import MutableMapping
import copy
import numpy as np

from gym import spaces
from gym import ObservationWrapper



            

Reported by Pylint.

Too many branches (14/12)
Error

Line: 16 Column: 5

              class PixelObservationWrapper(ObservationWrapper):
    """Augment observations by pixel values."""

    def __init__(
        self, env, pixels_only=True, render_kwargs=None, pixel_keys=("pixels",)
    ):
        """Initializes a new pixel Wrapper.

        Args:

            

Reported by Pylint.

Too many local variables (16/15)
Error

Line: 16 Column: 5

              class PixelObservationWrapper(ObservationWrapper):
    """Augment observations by pixel values."""

    def __init__(
        self, env, pixels_only=True, render_kwargs=None, pixel_keys=("pixels",)
    ):
        """Initializes a new pixel Wrapper.

        Args:

            

Reported by Pylint.

Consider using Python 3 style super() without arguments
Error

Line: 42 Column: 9

                              specified `pixel_keys`.
        """

        super(PixelObservationWrapper, self).__init__(env)

        if render_kwargs is None:
            render_kwargs = {}

        for key in pixel_keys:

            

Reported by Pylint.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 51
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

                          render_kwargs.setdefault(key, {})

            render_mode = render_kwargs[key].pop("mode", "rgb_array")
            assert render_mode == "rgb_array", render_mode
            render_kwargs[key]["mode"] = "rgb_array"

        wrapped_observation_space = env.observation_space

        if isinstance(wrapped_observation_space, spaces.Box):

            

Reported by Bandit.

gym/wrappers/resize_observation.py
5 issues
Unable to import 'cv2'
Error

Line: 21 Column: 9

                      self.observation_space = Box(low=0, high=255, shape=obs_shape, dtype=np.uint8)

    def observation(self, observation):
        import cv2

        observation = cv2.resize(
            observation, self.shape[::-1], interpolation=cv2.INTER_AREA
        )
        if observation.ndim == 2:

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import numpy as np
from gym.spaces import Box
from gym import ObservationWrapper


class ResizeObservation(ObservationWrapper):
    r"""Downsample the image observation to a square image."""

    def __init__(self, env, shape):

            

Reported by Pylint.

Consider using Python 3 style super() without arguments
Error

Line: 10 Column: 9

                  r"""Downsample the image observation to a square image."""

    def __init__(self, env, shape):
        super(ResizeObservation, self).__init__(env)
        if isinstance(shape, int):
            shape = (shape, shape)
        assert all(x > 0 for x in shape), shape

        self.shape = tuple(shape)

            

Reported by Pylint.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 13
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

                      super(ResizeObservation, self).__init__(env)
        if isinstance(shape, int):
            shape = (shape, shape)
        assert all(x > 0 for x in shape), shape

        self.shape = tuple(shape)

        obs_shape = self.shape + self.observation_space.shape[2:]
        self.observation_space = Box(low=0, high=255, shape=obs_shape, dtype=np.uint8)

            

Reported by Bandit.

Import outside toplevel (cv2)
Error

Line: 21 Column: 9

                      self.observation_space = Box(low=0, high=255, shape=obs_shape, dtype=np.uint8)

    def observation(self, observation):
        import cv2

        observation = cv2.resize(
            observation, self.shape[::-1], interpolation=cv2.INTER_AREA
        )
        if observation.ndim == 2:

            

Reported by Pylint.

gym/envs/toy_text/hotter_colder.py
4 issues
Method 'render' is abstract in class 'Env' but is not overridden
Error

Line: 8 Column: 1

              from gym.utils import seeding


class HotterColder(gym.Env):
    """Hotter Colder
    The goal of hotter colder is to guess closer to a randomly selected number

    After each step the agent receives an observation of:
    0 - No guess yet submitted (only after reset)

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import numpy as np

import gym
from gym import spaces
from gym.utils import seeding


class HotterColder(gym.Env):
    """Hotter Colder

            

Reported by Pylint.

Too many instance attributes (9/7)
Error

Line: 8 Column: 1

              from gym.utils import seeding


class HotterColder(gym.Env):
    """Hotter Colder
    The goal of hotter colder is to guess closer to a randomly selected number

    After each step the agent receives an observation of:
    0 - No guess yet submitted (only after reset)

            

Reported by Pylint.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 54
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

                      elif isinstance(action, list):
            action = np.array(action)

        assert self.action_space.contains(action)

        if action < self.number:
            self.observation = 1

        elif action == self.number:

            

Reported by Bandit.

gym/envs/toy_text/guessing_game.py
4 issues
Method 'render' is abstract in class 'Env' but is not overridden
Error

Line: 8 Column: 1

              from gym.utils import seeding


class GuessingGame(gym.Env):
    """Number guessing game

    The object of the game is to guess within 1% of the randomly chosen number
    within 200 time steps


            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import numpy as np

import gym
from gym import spaces
from gym.utils import seeding


class GuessingGame(gym.Env):
    """Number guessing game

            

Reported by Pylint.

Too many instance attributes (9/7)
Error

Line: 8 Column: 1

              from gym.utils import seeding


class GuessingGame(gym.Env):
    """Number guessing game

    The object of the game is to guess within 1% of the randomly chosen number
    within 200 time steps


            

Reported by Pylint.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 69
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

                      elif isinstance(action, list):
            action = np.array(action)

        assert self.action_space.contains(action)

        if action < self.number:
            self.observation = 1

        elif action == self.number:

            

Reported by Bandit.

gym/wrappers/transform_observation.py
4 issues
Missing module docstring
Error

Line: 1 Column: 1

              from gym import ObservationWrapper


class TransformObservation(ObservationWrapper):
    r"""Transform the observation via an arbitrary function.

    Example::

        >>> import gym

            

Reported by Pylint.

Consider using Python 3 style super() without arguments
Error

Line: 22 Column: 9

                  """

    def __init__(self, env, f):
        super(TransformObservation, self).__init__(env)
        assert callable(f)
        self.f = f

    def observation(self, observation):
        return self.f(observation)

            

Reported by Pylint.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 23
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

              
    def __init__(self, env, f):
        super(TransformObservation, self).__init__(env)
        assert callable(f)
        self.f = f

    def observation(self, observation):
        return self.f(observation)

            

Reported by Bandit.

Attribute name "f" doesn't conform to snake_case naming style
Error

Line: 24 Column: 9

                  def __init__(self, env, f):
        super(TransformObservation, self).__init__(env)
        assert callable(f)
        self.f = f

    def observation(self, observation):
        return self.f(observation)

            

Reported by Pylint.