Skip to content

Commit

Permalink
Ruff: Enable "R". Remove pylint.
Browse files Browse the repository at this point in the history
  • Loading branch information
heiner authored and Heinrich Kuttler committed May 4, 2024
1 parent 9720e93 commit 1dfef0c
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 39 deletions.
5 changes: 2 additions & 3 deletions nle/agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,9 @@
def nested_map(f, n):
if isinstance(n, tuple) or isinstance(n, list):
return n.__class__(nested_map(f, sn) for sn in n)
elif isinstance(n, dict):
if isinstance(n, dict):
return {k: nested_map(f, v) for k, v in n.items()}
else:
return f(n)
return f(n)


def compute_baseline_loss(advantages):
Expand Down
2 changes: 0 additions & 2 deletions nle/dataset/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# TODO(heiner): Consider using __all__ as ruff suggests.

from nle._pyconverter import Converter
import nle.dataset.db
from nle.dataset.populate_db import add_altorg_directory, add_nledata_directory
Expand Down
4 changes: 2 additions & 2 deletions nle/env/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ def render(self, mode="human"):
tty_colors = obs[self._observation_keys.index("tty_colors")]
tty_cursor = obs[self._observation_keys.index("tty_cursor")]
print(nethack.tty_render(tty_chars, tty_colors, tty_cursor))
return
return None

if mode == "full":
message_index = self._observation_keys.index("message")
Expand All @@ -509,7 +509,7 @@ def render(self, mode="human"):
chars = self.last_observation[self._observation_keys.index("chars")]
colors = self.last_observation[self._observation_keys.index("colors")]
print(nethack.tty_render(chars, colors))
return
return None

if mode in ("ansi", "string"): # Misnomer: This is the least ANSI of them all.
chars = self.last_observation[self._observation_keys.index("chars")]
Expand Down
4 changes: 0 additions & 4 deletions nle/nethack/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
# Copyright (c) Facebook, Inc. and its affiliates.

# TODO(heiner): Consider using __all__ as ruff suggests.
# ruff: noqa

from nle.nethack.actions import * # noqa: F403
from nle._pynethack.nethack import * # noqa: F403
from nle.nethack.nethack import (
Expand Down
2 changes: 1 addition & 1 deletion nle/nethack/nethack.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def set_current_seeds(self, core=None, disp=None, reseed=False):
seeds = [core, disp, reseed]
if any(s is None for s in seeds):
if all(s is None for s in seeds):
return
return None
for i, (s, s0) in enumerate(zip(seeds, self.get_current_seeds())):
if s is None:
seeds[i] = s0
Expand Down
9 changes: 4 additions & 5 deletions nle/scripts/collect_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,13 @@ def get_nvidia_smi():
def get_platform():
if sys.platform.startswith("linux"):
return "linux"
elif sys.platform.startswith("win32"):
if sys.platform.startswith("win32"):
return "win32"
elif sys.platform.startswith("cygwin"):
if sys.platform.startswith("cygwin"):
return "cygwin"
elif sys.platform.startswith("darwin"):
if sys.platform.startswith("darwin"):
return "darwin"
else:
return sys.platform
return sys.platform


def get_mac_version(run_lambda):
Expand Down
7 changes: 3 additions & 4 deletions nle/scripts/read_tty.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,15 @@ def getfile(filename):
f = os.fdopen(os.dup(0), "rb")
os.dup2(1, 0)
return f
elif os.path.splitext(filename)[1] in (".bz2", ".bzip2"):
if os.path.splitext(filename)[1] in (".bz2", ".bzip2"):
import bz2

return bz2.BZ2File(filename)
elif os.path.splitext(filename)[1] in (".gz", ".gzip"):
if os.path.splitext(filename)[1] in (".gz", ".gzip"):
import gzip

return gzip.GzipFile(filename)
else:
return open(filename, "rb")
return open(filename, "rb")


def color(s, value):
Expand Down
19 changes: 1 addition & 18 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,6 @@ force_single_line = true
profile = "black"
skip_glob = "**/__init__.py"

[tool.pylint.messages_control]
disable = [
"missing-class-docstring",
"invalid-name", # pylint is very strict.
"missing-class-docstring",
"missing-function-docstring",
"missing-module-docstring",
"c-extension-no-member",
"no-member", # too many false positives.
]
[tool.pylint.typecheck]
generated-members=["numpy.*", "torch.*", "nle._pynethack.*"]
[tool.pylint.design]
max-args=15 # Maximum number of arguments for function / method.
max-attributes=50 # Maximum number of attributes for a class (see R0902).
max-bool-expr=5 # Maximum number of boolean expressions in an if statement (see R0916).
max-branches=15 # Maximum number of branch for function / method body.
max-locals=30 # Maximum number of locals for function / method body.
[tool.ruff]
# See https://docs.astral.sh/ruff/rules/.
extend-exclude = [
Expand All @@ -55,6 +37,7 @@ select = [
"E",
"F",
"W",
"R",
]
[tool.ruff.lint.flake8-comprehensions]
allow-dict-calls-with-keyword-arguments = true
Expand Down

0 comments on commit 1dfef0c

Please sign in to comment.