Skip to content

Commit c71a83b

Browse files
aelanmanjrs65
authored andcommitted
style: blacken code and suppress some pylint warnings
1 parent 61747d5 commit c71a83b

File tree

9 files changed

+29
-21
lines changed

9 files changed

+29
-21
lines changed

.github/workflows/main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
run: flake8 --show-source --ignore=E501,E741,E203,W503,E266,E402,D105,D107 coco
3636

3737
- name: Run pylint
38-
run: pylint-ignore -d line-too-long,invalid-name,logging-fstring-interpolation,too-many-arguments,too-many-instance-attributes,too-many-locals,cyclic-import --ignore=_version.py coco
38+
run: pylint-ignore -d line-too-long,invalid-name,logging-fstring-interpolation,too-many-arguments,too-many-instance-attributes,too-many-locals,cyclic-import,C0206 --ignore=_version.py coco
3939

4040
tests:
4141
runs-on: ubuntu-latest

coco/_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class NotThisMethod(Exception):
5656

5757

5858
def register_vcs_handler(vcs, method): # decorator
59-
"""Mark a method as the handler for a particular VCS."""
59+
"""Decorator to mark a method as the handler for a particular VCS."""
6060

6161
def decorate(f):
6262
"""Store f in HANDLERS[vcs][method]."""

coco/config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def load_config(path=None):
172172

173173
logger.info(f"Loading config file {cfile}")
174174

175-
with absfile.open("r") as fh:
175+
with absfile.open("r", encoding="utf-8") as fh:
176176
conf = yaml.safe_load(fh)
177177

178178
config = merge_dict_tree(config, conf)

coco/core.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ def check(e):
392392
a = list(a.keys())[0]
393393
if isinstance(a, CocoForward):
394394
a = a.name
395-
if a not in self.endpoints.keys():
395+
if a not in self.endpoints:
396396
raise ConfigError(
397397
f"coco.endpoint: endpoint `{a}` found in config for "
398398
f"`{e.name}` does not exist."

coco/request_forwarder.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
logger = logging.getLogger(__name__)
2222

2323

24-
async def _dump_trace(session, context, params):
24+
async def _dump_trace(session, context, params): # pylint: disable=W0613
2525
"""Tracing call back that dumps the current info."""
2626
events_seen = ", ".join(
2727
[
@@ -45,7 +45,7 @@ def _create_trace_callback(name):
4545
The callbacks will track which events were seen at what time.
4646
"""
4747

48-
async def _callback(session, context, params):
48+
async def _callback(session, context, params): # pylint: disable=W0613
4949

5050
if not hasattr(context, "event_status"):
5151
context.event_status = {}
@@ -56,10 +56,10 @@ async def _callback(session, context, params):
5656
return _callback
5757

5858

59-
def _trace_config(all=False):
59+
def _trace_config(trace_all=False):
6060
"""Get a trace config for debugging.
6161
62-
If all=False, only dump on exceptions, otherwise dump at the end of a request too.
62+
If trace_all=False, only dump on exceptions, otherwise dump at the end of a request too.
6363
"""
6464
if not hasattr(_trace_config, "obj"):
6565

@@ -74,7 +74,7 @@ def _trace_config(all=False):
7474

7575
_trace_config.obj.on_request_exception.append(_dump_trace)
7676

77-
if all:
77+
if trace_all:
7878
_trace_config.obj.on_request_end.append(_dump_trace)
7979

8080
return _trace_config.obj

coco/test/coco_runner.py

+14-8
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
import shutil
1010
import time
1111

12-
STATE_DIR = tempfile.TemporaryDirectory()
13-
BLOCKLIST_DIR = tempfile.TemporaryDirectory()
12+
STATE_DIR = tempfile.TemporaryDirectory() # pylint: disable=R1732
13+
BLOCKLIST_DIR = tempfile.TemporaryDirectory() # pylint: disable=R1732
1414
BLOCKLIST_PATH = pathlib.Path(BLOCKLIST_DIR.name, "blocklist.json")
1515

1616
COCO_DAEMON = (
@@ -61,11 +61,13 @@ def __del__(self):
6161
def __enter__(self):
6262
return self
6363

64-
def __exit__(self, type, value, traceback):
64+
def __exit__(self, exc_type, value, traceback):
6565
self.__del__()
6666

67-
def client(self, command, data=[], silent=False):
67+
def client(self, command, data=None, silent=False):
6868
"""Make coco-client script call a coco endpoint."""
69+
if data is None:
70+
data = []
6971
cmd = CLIENT_ARGS + ["-c", self.configfile.name, command] + data
7072
logger.debug(f"calling coco client: {cmd}")
7173
try:
@@ -90,24 +92,28 @@ def start_coco(self, config, endpoint_configs, reset):
9092
CONFIG.update(config)
9193

9294
# Write endpoint configs to file
93-
self.endpointdir = tempfile.TemporaryDirectory()
95+
self.endpointdir = tempfile.TemporaryDirectory() # pylint: disable=R1732
9496
CONFIG["endpoint_dir"] = self.endpointdir.name
9597
for name, endpoint_conf in endpoint_configs.items():
9698
with open(
97-
os.path.join(self.endpointdir.name, name + ".conf"), "w"
99+
os.path.join(self.endpointdir.name, name + ".conf"),
100+
"w",
101+
encoding="utf-8",
98102
) as outfile:
99103
json.dump(endpoint_conf, outfile)
100104

101105
# Write config to file
102-
self.configfile = tempfile.NamedTemporaryFile("w")
106+
self.configfile = tempfile.NamedTemporaryFile("w") # pylint: disable=R1732
103107
json.dump(CONFIG, self.configfile)
104108
self.configfile.flush()
105109

106110
args = []
107111
if reset:
108112
args.append("--reset")
109113

110-
self.coco = subprocess.Popen([COCO_DAEMON, "-c", self.configfile.name, *args])
114+
self.coco = subprocess.Popen(
115+
[COCO_DAEMON, "-c", self.configfile.name, *args]
116+
) # pylint: disable=R1732
111117

112118
def stop_coco(self):
113119
"""Stop coco script."""

coco/test/endpoint_farm.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ def endpoint(name):
2727
try:
2828
reply = dict(request.json)
2929
except BadRequest:
30-
app.logger.info("Did not get a JSON message, using the empty {}")
30+
app.logger.info(
31+
"Did not get a JSON message, using the empty {}"
32+
) # pylint: disable=E1101
3133
reply = {}
3234

3335
if request.args:

coco/worker.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ async def go():
134134

135135
try:
136136
endpoint = endpoints[endpoint_name]
137-
except KeyError:
138-
raise InvalidPath(f"Endpoint /{endpoint_name} not found.")
137+
except KeyError as exc:
138+
raise InvalidPath(f"Endpoint /{endpoint_name} not found.") from exc
139139

140140
# Check that it is being requested with the correct method
141141
if method != endpoint.type and method not in endpoint.type:

docs/conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
#
5858
# This is also used if you do content translation via gettext catalogs.
5959
# Usually you set "language" from the command line for these cases.
60-
language = 'en'
60+
language = "en"
6161

6262
# List of patterns, relative to source directory, that match files and
6363
# directories to ignore when looking for source files.

0 commit comments

Comments
 (0)