The following issues were found

gym/envs/tests/test_mujoco_v2_to_v3_conversion.py
6 issues
Unused variable 'i'
Error

Line: 21 Column: 9

              
    np.testing.assert_allclose(old_reset_observation, new_reset_observation)

    for i in range(num_actions):
        action = old_environment.action_space.sample()
        old_observation, old_reward, old_done, old_info = old_environment.step(action)
        new_observation, new_reward, new_done, new_info = new_environment.step(action)

        eps = 1e-6

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import unittest
import numpy as np
from gym import envs
from gym.envs.tests.spec_list import skip_mujoco, SKIP_MUJOCO_WARNING_MESSAGE


def verify_environments_match(
    old_environment_id, new_environment_id, seed=1, num_actions=1000
):

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 7 Column: 1

              from gym.envs.tests.spec_list import skip_mujoco, SKIP_MUJOCO_WARNING_MESSAGE


def verify_environments_match(
    old_environment_id, new_environment_id, seed=1, num_actions=1000
):
    old_environment = envs.make(old_environment_id)
    new_environment = envs.make(new_environment_id)


            

Reported by Pylint.

Too many local variables (20/15)
Error

Line: 7 Column: 1

              from gym.envs.tests.spec_list import skip_mujoco, SKIP_MUJOCO_WARNING_MESSAGE


def verify_environments_match(
    old_environment_id, new_environment_id, seed=1, num_actions=1000
):
    old_environment = envs.make(old_environment_id)
    new_environment = envs.make(new_environment_id)


            

Reported by Pylint.

Missing class docstring
Error

Line: 36 Column: 1

              

@unittest.skipIf(skip_mujoco, SKIP_MUJOCO_WARNING_MESSAGE)
class Mujocov2Tov3ConversionTest(unittest.TestCase):
    def test_environments_match(self):
        test_cases = (
            {"old_id": "Swimmer-v2", "new_id": "Swimmer-v3"},
            {"old_id": "Hopper-v2", "new_id": "Hopper-v3"},
            {"old_id": "Walker2d-v2", "new_id": "Walker2d-v3"},

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 37 Column: 5

              
@unittest.skipIf(skip_mujoco, SKIP_MUJOCO_WARNING_MESSAGE)
class Mujocov2Tov3ConversionTest(unittest.TestCase):
    def test_environments_match(self):
        test_cases = (
            {"old_id": "Swimmer-v2", "new_id": "Swimmer-v3"},
            {"old_id": "Hopper-v2", "new_id": "Hopper-v3"},
            {"old_id": "Walker2d-v2", "new_id": "Walker2d-v3"},
            {"old_id": "HalfCheetah-v2", "new_id": "HalfCheetah-v3"},

            

Reported by Pylint.

tests/gym/envs/robotics/hand/test_manipulate_touch_sensors.py
6 issues
Unable to import 'pytest'
Error

Line: 3 Column: 1

              import pickle

import pytest

from gym import envs
from gym.envs.tests.spec_list import skip_mujoco, SKIP_MUJOCO_WARNING_MESSAGE


ENVIRONMENT_IDS = (

            

Reported by Pylint.

Pickle and modules that wrap it can be unsafe when used to deserialize untrusted data, possible security issue.
Security blacklist

Line: 21
Suggestion: https://bandit.readthedocs.io/en/latest/blacklists/blacklist_calls.html#b301-pickle

              def test_serialize_deserialize(environment_id):
    env1 = envs.make(environment_id, target_position="fixed")
    env1.reset()
    env2 = pickle.loads(pickle.dumps(env1))

    assert env1.target_position == env2.target_position, (
        env1.target_position,
        env2.target_position,
    )

            

Reported by Bandit.

Missing module docstring
Error

Line: 1 Column: 1

              import pickle

import pytest

from gym import envs
from gym.envs.tests.spec_list import skip_mujoco, SKIP_MUJOCO_WARNING_MESSAGE


ENVIRONMENT_IDS = (

            

Reported by Pylint.

Consider possible security implications associated with pickle module.
Security blacklist

Line: 1
Suggestion: https://bandit.readthedocs.io/en/latest/blacklists/blacklist_imports.html#b403-import-pickle

              import pickle

import pytest

from gym import envs
from gym.envs.tests.spec_list import skip_mujoco, SKIP_MUJOCO_WARNING_MESSAGE


ENVIRONMENT_IDS = (

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 18 Column: 1

              
@pytest.mark.skipif(skip_mujoco, reason=SKIP_MUJOCO_WARNING_MESSAGE)
@pytest.mark.parametrize("environment_id", ENVIRONMENT_IDS)
def test_serialize_deserialize(environment_id):
    env1 = envs.make(environment_id, target_position="fixed")
    env1.reset()
    env2 = pickle.loads(pickle.dumps(env1))

    assert env1.target_position == env2.target_position, (

            

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

                  env1.reset()
    env2 = pickle.loads(pickle.dumps(env1))

    assert env1.target_position == env2.target_position, (
        env1.target_position,
        env2.target_position,
    )

            

Reported by Bandit.

setup.py
6 issues
Unable to import 'version'
Error

Line: 8 Column: 1

              
# Don't import gym module here, since deps may not be installed
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "gym"))
from version import VERSION

# Environment-specific dependencies.
extras = {
    "atari": ["atari-py==0.2.6", "opencv-python>=3."],
    "box2d": ["box2d-py~=2.3.5", "pyglet>=1.4.0"],

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import os.path
import sys

from setuptools import find_packages, setup

# Don't import gym module here, since deps may not be installed
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "gym"))
from version import VERSION


            

Reported by Pylint.

Import "from version import VERSION" should be placed at the top of the module
Error

Line: 8 Column: 1

              
# Don't import gym module here, since deps may not be installed
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "gym"))
from version import VERSION

# Environment-specific dependencies.
extras = {
    "atari": ["atari-py==0.2.6", "opencv-python>=3."],
    "box2d": ["box2d-py~=2.3.5", "pyglet>=1.4.0"],

            

Reported by Pylint.

Consider using a set comprehension
Error

Line: 23 Column: 5

              
# Meta dependency groups.
extras["nomujoco"] = list(
    set(
        [
            item
            for name, group in extras.items()
            if name != "mujoco" and name != "robotics"
            for item in group

            

Reported by Pylint.

Consider merging these comparisons with "in" to "name not in ('mujoco', 'robotics')"
Error

Line: 27 Column: 16

                      [
            item
            for name, group in extras.items()
            if name != "mujoco" and name != "robotics"
            for item in group
        ]
    )
)
extras["all"] = list(set([item for group in extras.values() for item in group]))

            

Reported by Pylint.

Consider using a set comprehension
Error

Line: 32 Column: 22

                      ]
    )
)
extras["all"] = list(set([item for group in extras.values() for item in group]))

setup(
    name="gym",
    version=VERSION,
    description="Gym: A universal API for reinforcement learning environments.",

            

Reported by Pylint.

gym/wrappers/test_flatten_observation.py
5 issues
Unable to import 'pytest'
Error

Line: 1 Column: 1

              import pytest

import numpy as np

import gym
from gym.wrappers import FlattenObservation
from gym import spaces



            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import pytest

import numpy as np

import gym
from gym.wrappers import FlattenObservation
from gym import spaces



            

Reported by Pylint.

Missing function or method docstring
Error

Line: 11 Column: 1

              

@pytest.mark.parametrize("env_id", ["Blackjack-v0", "KellyCoinflip-v0"])
def test_flatten_observation(env_id):
    env = gym.make(env_id)
    wrapped_env = FlattenObservation(env)

    obs = env.reset()
    wrapped_obs = wrapped_env.reset()

            

Reported by Pylint.

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

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

                      )
        wrapped_space = spaces.Box(-np.inf, np.inf, [1 + (300 + 1)], dtype=np.float32)

    assert space.contains(obs)
    assert wrapped_space.contains(wrapped_obs)

            

Reported by Bandit.

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

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

                      wrapped_space = spaces.Box(-np.inf, np.inf, [1 + (300 + 1)], dtype=np.float32)

    assert space.contains(obs)
    assert wrapped_space.contains(wrapped_obs)

            

Reported by Bandit.

gym/envs/algorithmic/reversed_addition.py
5 issues
Parameters differ from overridden 'target_from_input_data' method
Error

Line: 8 Column: 5

                  def __init__(self, rows=2, base=3):
        super(ReversedAdditionEnv, self).__init__(rows=rows, base=base, chars=False)

    def target_from_input_data(self, input_strings):
        curry = 0
        target = []
        for digits in input_strings:
            total = sum(digits) + curry
            target.append(total % self.base)

            

Reported by Pylint.

TODO: It seems like this time limit is so strict as to make
Error

Line: 25 Column: 3

                      # Quirk preserved for the sake of consistency: add the length of the
        # input rather than the length of the desired output (which may differ
        # if there's an extra carried digit).
        # TODO: It seems like this time limit is so strict as to make
        # Addition3-v0 unsolvable, since agents aren't even given enough time
        # steps to look at all the digits. (The solutions on the scoreboard
        # seem to only work by save-scumming.)
        return self.input_width * 2 + 4

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from gym.envs.algorithmic import algorithmic_env


class ReversedAdditionEnv(algorithmic_env.GridAlgorithmicEnv):
    def __init__(self, rows=2, base=3):
        super(ReversedAdditionEnv, self).__init__(rows=rows, base=base, chars=False)

    def target_from_input_data(self, input_strings):
        curry = 0

            

Reported by Pylint.

Missing class docstring
Error

Line: 4 Column: 1

              from gym.envs.algorithmic import algorithmic_env


class ReversedAdditionEnv(algorithmic_env.GridAlgorithmicEnv):
    def __init__(self, rows=2, base=3):
        super(ReversedAdditionEnv, self).__init__(rows=rows, base=base, chars=False)

    def target_from_input_data(self, input_strings):
        curry = 0

            

Reported by Pylint.

Consider using Python 3 style super() without arguments
Error

Line: 6 Column: 9

              
class ReversedAdditionEnv(algorithmic_env.GridAlgorithmicEnv):
    def __init__(self, rows=2, base=3):
        super(ReversedAdditionEnv, self).__init__(rows=rows, base=base, chars=False)

    def target_from_input_data(self, input_strings):
        curry = 0
        target = []
        for digits in input_strings:

            

Reported by Pylint.

gym/envs/box2d/test_lunar_lander.py
5 issues
Unable to import 'pytest'
Error

Line: 1 Column: 1

              import pytest

try:
    import Box2D
    from .lunar_lander import LunarLander, LunarLanderContinuous, demo_heuristic_lander
except ImportError:
    Box2D = None



            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import pytest

try:
    import Box2D
    from .lunar_lander import LunarLander, LunarLanderContinuous, demo_heuristic_lander
except ImportError:
    Box2D = None



            

Reported by Pylint.

Missing function or method docstring
Error

Line: 11 Column: 1

              

@pytest.mark.skipif(Box2D is None, reason="Box2D not installed")
def test_lunar_lander():
    _test_lander(LunarLander(), seed=0)


@pytest.mark.skipif(Box2D is None, reason="Box2D not installed")
def test_lunar_lander_continuous():

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 16 Column: 1

              

@pytest.mark.skipif(Box2D is None, reason="Box2D not installed")
def test_lunar_lander_continuous():
    _test_lander(LunarLanderContinuous(), seed=0)


@pytest.mark.skipif(Box2D is None, reason="Box2D not installed")
def _test_lander(env, seed=None, render=False):

            

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

              @pytest.mark.skipif(Box2D is None, reason="Box2D not installed")
def _test_lander(env, seed=None, render=False):
    total_reward = demo_heuristic_lander(env, seed=seed, render=render)
    assert total_reward > 100

            

Reported by Bandit.

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

Line: 11 Column: 5

                      mujoco_env.MujocoEnv.__init__(self, "hopper.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 HopperEnv(mujoco_env.MujocoEnv, utils.EzPickle):
    def __init__(self):
        mujoco_env.MujocoEnv.__init__(self, "hopper.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 HopperEnv(mujoco_env.MujocoEnv, utils.EzPickle):
    def __init__(self):
        mujoco_env.MujocoEnv.__init__(self, "hopper.xml", 4)
        utils.EzPickle.__init__(self)

    def step(self, a):

            

Reported by Pylint.

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

Line: 19 Column: 9

                      reward = (posafter - posbefore) / self.dt
        reward += alive_bonus
        reward -= 1e-3 * np.square(a).sum()
        s = self.state_vector()
        done = not (
            np.isfinite(s).all()
            and (np.abs(s[2:]) < 100).all()
            and (height > 0.7)
            and (abs(ang) < 0.2)

            

Reported by Pylint.

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

Line: 26 Column: 9

                          and (height > 0.7)
            and (abs(ang) < 0.2)
        )
        ob = self._get_obs()
        return ob, reward, done, {}

    def _get_obs(self):
        return np.concatenate(
            [self.sim.data.qpos.flat[1:], np.clip(self.sim.data.qvel.flat, -10, 10)]

            

Reported by Pylint.

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

Line: 30 Column: 5

                          ]
        )

    def step(self, a):
        pos_before = mass_center(self.model, self.sim)
        self.do_simulation(a, self.frame_skip)
        pos_after = mass_center(self.model, self.sim)
        alive_bonus = 5.0
        data = self.sim.data

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

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


def mass_center(model, sim):
    mass = np.expand_dims(model.body_mass, 1)
    xpos = sim.data.xipos
    return (np.sum(mass * xpos, 0) / np.sum(mass))[0]

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 6 Column: 1

              from gym import utils


def mass_center(model, sim):
    mass = np.expand_dims(model.body_mass, 1)
    xpos = sim.data.xipos
    return (np.sum(mass * xpos, 0) / np.sum(mass))[0]



            

Reported by Pylint.

Missing class docstring
Error

Line: 12 Column: 1

                  return (np.sum(mass * xpos, 0) / np.sum(mass))[0]


class HumanoidEnv(mujoco_env.MujocoEnv, utils.EzPickle):
    def __init__(self):
        mujoco_env.MujocoEnv.__init__(self, "humanoid.xml", 5)
        utils.EzPickle.__init__(self)

    def _get_obs(self):

            

Reported by Pylint.

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

Line: 56 Column: 9

                      )

    def reset_model(self):
        c = 0.01
        self.set_state(
            self.init_qpos + self.np_random.uniform(low=-c, high=c, size=self.model.nq),
            self.init_qvel
            + self.np_random.uniform(
                low=-c,

            

Reported by Pylint.

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

Line: 11 Column: 5

                      utils.EzPickle.__init__(self)
        mujoco_env.MujocoEnv.__init__(self, "inverted_pendulum.xml", 2)

    def step(self, a):
        reward = 1.0
        self.do_simulation(a, self.frame_skip)
        ob = self._get_obs()
        notdone = np.isfinite(ob).all() and (np.abs(ob[1]) <= 0.2)
        done = not notdone

            

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 InvertedPendulumEnv(mujoco_env.MujocoEnv, utils.EzPickle):
    def __init__(self):
        utils.EzPickle.__init__(self)
        mujoco_env.MujocoEnv.__init__(self, "inverted_pendulum.xml", 2)

            

Reported by Pylint.

Missing class docstring
Error

Line: 6 Column: 1

              from gym.envs.mujoco import mujoco_env


class InvertedPendulumEnv(mujoco_env.MujocoEnv, utils.EzPickle):
    def __init__(self):
        utils.EzPickle.__init__(self)
        mujoco_env.MujocoEnv.__init__(self, "inverted_pendulum.xml", 2)

    def step(self, a):

            

Reported by Pylint.

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

Line: 14 Column: 9

                  def step(self, a):
        reward = 1.0
        self.do_simulation(a, self.frame_skip)
        ob = self._get_obs()
        notdone = np.isfinite(ob).all() and (np.abs(ob[1]) <= 0.2)
        done = not notdone
        return ob, reward, done, {}

    def reset_model(self):

            

Reported by Pylint.

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

Line: 33 Column: 9

                      return np.concatenate([self.sim.data.qpos, self.sim.data.qvel]).ravel()

    def viewer_setup(self):
        v = self.viewer
        v.cam.trackbodyid = 0
        v.cam.distance = self.model.stat.extent

            

Reported by Pylint.

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

Line: 11 Column: 5

                      utils.EzPickle.__init__(self)
        mujoco_env.MujocoEnv.__init__(self, "reacher.xml", 2)

    def step(self, a):
        vec = self.get_body_com("fingertip") - self.get_body_com("target")
        reward_dist = -np.linalg.norm(vec)
        reward_ctrl = -np.square(a).sum()
        reward = reward_dist + reward_ctrl
        self.do_simulation(a, self.frame_skip)

            

Reported by Pylint.

Attribute 'goal' defined outside __init__
Error

Line: 30 Column: 13

                          + self.init_qpos
        )
        while True:
            self.goal = self.np_random.uniform(low=-0.2, high=0.2, size=2)
            if np.linalg.norm(self.goal) < 0.2:
                break
        qpos[-2:] = self.goal
        qvel = self.init_qvel + self.np_random.uniform(
            low=-0.005, high=0.005, size=self.model.nv

            

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 ReacherEnv(mujoco_env.MujocoEnv, utils.EzPickle):
    def __init__(self):
        utils.EzPickle.__init__(self)
        mujoco_env.MujocoEnv.__init__(self, "reacher.xml", 2)

            

Reported by Pylint.

Missing class docstring
Error

Line: 6 Column: 1

              from gym.envs.mujoco import mujoco_env


class ReacherEnv(mujoco_env.MujocoEnv, utils.EzPickle):
    def __init__(self):
        utils.EzPickle.__init__(self)
        mujoco_env.MujocoEnv.__init__(self, "reacher.xml", 2)

    def step(self, a):

            

Reported by Pylint.

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

Line: 17 Column: 9

                      reward_ctrl = -np.square(a).sum()
        reward = reward_dist + 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.