Skip to content

Commit

Permalink
Used pyupgrade with --py3-plus. [1/2] (#517)
Browse files Browse the repository at this point in the history
* Used pyupgrade with --py3-plus.

* Revert some changes to make the review easier.

* Pep8

* fix pep8
  • Loading branch information
gabrieldemarmiesse authored and JarnoRFB committed Jul 18, 2019
1 parent 4b4158b commit 1fd0f07
Show file tree
Hide file tree
Showing 15 changed files with 37 additions and 39 deletions.
16 changes: 8 additions & 8 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
master_doc = 'index'

# General information about the project.
project = u'Sacred'
copyright = u'2015, Klaus Greff'
project = 'Sacred'
copyright = '2015, Klaus Greff'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down Expand Up @@ -213,8 +213,8 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
('index', 'Sacred.tex', u'Sacred Documentation',
u'Klaus Greff', 'manual'),
('index', 'Sacred.tex', 'Sacred Documentation',
'Klaus Greff', 'manual'),
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down Expand Up @@ -243,8 +243,8 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'sacred', u'Sacred Documentation',
[u'Klaus Greff'], 1)
('index', 'sacred', 'Sacred Documentation',
['Klaus Greff'], 1)
]

# If true, show URL addresses after external links.
Expand All @@ -257,8 +257,8 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'Sacred', u'Sacred Documentation',
u'Klaus Greff', 'Sacred', 'One line description of project.',
('index', 'Sacred', 'Sacred Documentation',
'Klaus Greff', 'Sacred', 'One line description of project.',
'Miscellaneous'),
]

Expand Down
2 changes: 1 addition & 1 deletion examples/captured_out_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def write_and_flush(*args):
sys.stdout.flush()


class ProgressMonitor(object):
class ProgressMonitor:
def __init__(self, count):
self.count, self.progress = count, 0

Expand Down
6 changes: 3 additions & 3 deletions sacred/arg_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def _format_options_usage(options):
subsequent_indent=' ' * 32)
wrapped_description = "\n".join(wrapped_description).strip()

options_usage += " {0:28} {1}\n".format(flag, wrapped_description)
options_usage += " {:28} {}\n".format(flag, wrapped_description)
return options_usage


Expand Down Expand Up @@ -133,8 +133,8 @@ def _format_arguments_usage(options):
initial_indent=' ' * 12,
subsequent_indent=' ' * 12)
wrapped_description = "\n".join(wrapped_description).strip()
argument_usage += " {0:8} {1}\n".format(op.arg,
wrapped_description)
argument_usage += " {:8} {}\n".format(op.arg,
wrapped_description)
return argument_usage


Expand Down
2 changes: 1 addition & 1 deletion sacred/commandline_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def with_metaclass(meta, *bases):
class Metaclass(meta):
def __new__(cls, name, this_bases, d):
return meta(name, bases, d)
return type.__new__(Metaclass, str('temporary_class'), (), {})
return type.__new__(Metaclass, 'temporary_class', (), {})


def parse_mod_deps(depends_on):
Expand Down
4 changes: 2 additions & 2 deletions sacred/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def get_commit_if_possible(filename):


@functools.total_ordering
class Source(object):
class Source:
def __init__(self, filename, digest, repo, commit, isdirty):
self.filename = filename
self.digest = digest
Expand Down Expand Up @@ -189,7 +189,7 @@ def __repr__(self):


@functools.total_ordering
class PackageDependency(object):
class PackageDependency:
modname_to_dist = {}

def __init__(self, name, version):
Expand Down
10 changes: 5 additions & 5 deletions sacred/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ def __init__(self, name=None, ingredients=(), interactive=False,
name = name[:-3]
elif name.endswith('.pyc'):
name = name[:-4]
super(Experiment, self).__init__(path=name,
ingredients=ingredients,
interactive=interactive,
base_dir=base_dir,
_caller_globals=caller_globals)
super().__init__(path=name,
ingredients=ingredients,
interactive=interactive,
base_dir=base_dir,
_caller_globals=caller_globals)
self.default_command = None
self.command(print_config, unobserved=True)
self.command(print_dependencies, unobserved=True)
Expand Down
10 changes: 4 additions & 6 deletions sacred/ingredient.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@ def gather_from_ingredients(wrapped, instance=None, args=None, kwargs=None):
This function is necessary, because `Ingredient._gather` cannot directly be
used as a decorator inside of `Ingredient`.
"""
for item in instance._gather(wrapped):
yield item
yield from instance._gather(wrapped)


class Ingredient(object):
class Ingredient:
"""
Ingredients are reusable parts of experiments.
Expand Down Expand Up @@ -228,7 +227,7 @@ def _create_config_dict(cfg_or_file, kw_conf):
return ConfigDict(cfg_or_file)
elif isinstance(cfg_or_file, str):
if not os.path.exists(cfg_or_file):
raise IOError('File not found {}'.format(cfg_or_file))
raise OSError('File not found {}'.format(cfg_or_file))
abspath = os.path.abspath(cfg_or_file)
return ConfigDict(load_config_file(abspath))
else:
Expand Down Expand Up @@ -292,8 +291,7 @@ def _gather(self, func):
example.
"""
for ingredient, _ in self.traverse_ingredients():
for item in func(ingredient):
yield item
yield from func(ingredient)

@gather_from_ingredients
def gather_commands(self, ingredient):
Expand Down
2 changes: 1 addition & 1 deletion sacred/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from sacred.settings import SETTINGS


class Scaffold(object):
class Scaffold:
def __init__(self, config_scopes, subrunners, path, captured_functions,
commands, named_configs, config_hooks, generate_seed):
self.config_scopes = config_scopes
Expand Down
2 changes: 1 addition & 1 deletion sacred/metrics_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from queue import Queue, Empty


class MetricsLogger(object):
class MetricsLogger:
"""MetricsLogger collects metrics measured during experiments.
MetricsLogger is the (only) part of the Metrics API.
Expand Down
2 changes: 1 addition & 1 deletion sacred/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from sacred.stdout_capturing import get_stdcapturer


class Run(object):
class Run:
"""Represent and manage a single run of an experiment."""

def __init__(self, config, config_modifications, main_function, observers,
Expand Down
8 changes: 4 additions & 4 deletions sacred/stdout_capturing.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ def flush():
try:
sys.stdout.flush()
sys.stderr.flush()
except (AttributeError, ValueError, IOError):
except (AttributeError, ValueError, OSError):
pass # unsupported
try:
libc.fflush(None)
except (AttributeError, ValueError, IOError):
except (AttributeError, ValueError, OSError):
pass # unsupported


Expand All @@ -41,7 +41,7 @@ class TeeingStreamProxy(wrapt.ObjectProxy):
"""A wrapper around stdout or stderr that duplicates all output to out."""

def __init__(self, wrapped, out):
super(TeeingStreamProxy, self).__init__(wrapped)
super().__init__(wrapped)
self._self_out = out

def write(self, data):
Expand All @@ -53,7 +53,7 @@ def flush(self):
self._self_out.flush()


class CapturedStdout(object):
class CapturedStdout:
def __init__(self, buffer):
self.buffer = buffer
self.read_position = 0
Expand Down
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from sacred.settings import SETTINGS

EXAMPLES_PATH = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'examples')
BLOCK_START = re.compile('^\s\s+\$.*$', flags=re.MULTILINE)
BLOCK_START = re.compile(r'^\s\s+\$.*$', flags=re.MULTILINE)


def get_calls_from_doc(doc):
Expand Down Expand Up @@ -45,7 +45,7 @@ def pytest_generate_tests(metafunc):
if 'example_test' in metafunc.fixturenames:
examples = [os.path.splitext(f)[0] for f in os.listdir(EXAMPLES_PATH)
if os.path.isfile(os.path.join(EXAMPLES_PATH, f)) and
f.endswith('.py') and f != '__init__.py' and re.match('^\d', f)]
f.endswith('.py') and f != '__init__.py' and re.match(r'^\d', f)]

sys.path.append(EXAMPLES_PATH)
example_tests = []
Expand Down
2 changes: 1 addition & 1 deletion tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_non_unicode_repr():
p = pprint.PrettyPrinter()
p.format = _non_unicode_repr
# make sure there is no u' in the representation
assert p.pformat(u'HelloWorld') == "'HelloWorld'"
assert p.pformat('HelloWorld') == "'HelloWorld'"


@pytest.fixture
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ingredients.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def test_add_config_file(ing):


def test_add_config_file_nonexisting_raises(ing):
with pytest.raises(IOError):
with pytest.raises(OSError):
ing.add_config("nonexistens.json")


Expand Down
4 changes: 2 additions & 2 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def test_is_subdirectory(path, parent, expected):


def test_get_inheritors():
class A(object):
class A:
pass

class B(A):
Expand All @@ -132,7 +132,7 @@ class C(B):
class D(A):
pass

class E(object):
class E:
pass

assert get_inheritors(A) == {B, C, D}
Expand Down

0 comments on commit 1fd0f07

Please sign in to comment.