Skip to content

Commit

Permalink
Remove Python 2.x import hacks.
Browse files Browse the repository at this point in the history
Switch to f-strings.
  • Loading branch information
CodeReclaimers committed Apr 30, 2022
1 parent 8e579dd commit 39d6719
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 22 deletions.
23 changes: 7 additions & 16 deletions neat/distributed.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,14 @@
``chunksize`` elements.
"""

import multiprocessing
import queue
import socket
import sys
import time
import warnings

# below still needed for queue.Empty
try:
# pylint: disable=import-error
import Queue as queue
except ImportError:
# pylint: disable=import-error
import queue

import multiprocessing
from multiprocessing import managers
from argparse import Namespace
from multiprocessing import managers

# Some of this code is based on
# http://eli.thegreenplace.net/2012/01/24/distributed-computing-in-python-with-multiprocessing
Expand Down Expand Up @@ -145,7 +137,7 @@ def _determine_mode(addr, mode):
elif mode in (MODE_SECONDARY, MODE_PRIMARY):
return mode
else:
raise ValueError("Invalid mode {!r}!".format(mode))
raise ValueError(f"Invalid mode {mode!r}!")


def chunked(data, chunksize):
Expand Down Expand Up @@ -208,9 +200,8 @@ def set_secondary_state(self, value):
"""Sets the value for 'secondary_state'."""
if value not in (_STATE_RUNNING, _STATE_SHUTDOWN, _STATE_FORCED_SHUTDOWN):
raise ValueError(
"State {!r} is invalid - needs to be one of _STATE_RUNNING, _STATE_SHUTDOWN, or _STATE_FORCED_SHUTDOWN".format(
value)
)
f"State {value!r} is invalid - needs to be one of _STATE_RUNNING, _STATE_SHUTDOWN, or _STATE_FORCED_SHUTDOWN")

if self.manager is None:
raise RuntimeError("Manager not started")
self.manager.set_state(value)
Expand Down Expand Up @@ -422,7 +413,7 @@ def start(self, exit_on_stop=True, secondary_wait=0, reconnect=False):
if exit_on_stop:
sys.exit(0)
else:
raise ValueError("Invalid mode {!r}!".format(self.mode))
raise ValueError(f"Invalid mode {self.mode!r}!")

def stop(self, wait=1, shutdown=True, force_secondary_shutdown=False):
"""
Expand Down
7 changes: 1 addition & 6 deletions neat/threaded.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@
else:
HAVE_THREADS = True

try:
# pylint: disable=import-error
import Queue as queue
except ImportError:
# pylint: disable=import-error
import queue
import queue


class ThreadedEvaluator(object):
Expand Down

0 comments on commit 39d6719

Please sign in to comment.