From 69de983af0f28149c4d400e73f8d6a11eec42ddc Mon Sep 17 00:00:00 2001 From: Mathieu Dupuy Date: Fri, 8 Sep 2023 11:48:11 +0200 Subject: [PATCH] remove python2-ism in the code We don't need all these in python3. I used `pyupgrade --py-36plus dparse tests`. --- dparse/__init__.py | 2 -- dparse/dependencies.py | 7 ++----- dparse/errors.py | 4 ---- dparse/filetypes.py | 3 --- dparse/parser.py | 12 ++++-------- dparse/regex.py | 3 --- dparse/updater.py | 8 +++----- tests/__init__.py | 2 -- tests/test_dependencies.py | 2 -- tests/test_parse.py | 2 -- tests/test_updater.py | 1 - 11 files changed, 9 insertions(+), 37 deletions(-) diff --git a/dparse/__init__.py b/dparse/__init__.py index 4ca42d0..ee91a24 100644 --- a/dparse/__init__.py +++ b/dparse/__init__.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals, absolute_import """Top-level package for Dependency Parser.""" __author__ = """Jannis Gebauer""" diff --git a/dparse/dependencies.py b/dparse/dependencies.py index 9e8d8c1..d885b6c 100644 --- a/dparse/dependencies.py +++ b/dparse/dependencies.py @@ -1,13 +1,10 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals, absolute_import - import json from json import JSONEncoder from . import filetypes, errors -class Dependency(object): +class Dependency: """ """ @@ -102,7 +99,7 @@ def default(self, o): return JSONEncoder.default(self, o) -class DependencyFile(object): +class DependencyFile: """ """ diff --git a/dparse/errors.py b/dparse/errors.py index 74fc99d..e5a3f94 100644 --- a/dparse/errors.py +++ b/dparse/errors.py @@ -1,7 +1,3 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals, absolute_import - - class UnknownDependencyFileError(Exception): """ diff --git a/dparse/filetypes.py b/dparse/filetypes.py index eadfff4..573c836 100644 --- a/dparse/filetypes.py +++ b/dparse/filetypes.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals, absolute_import - requirements_txt = "requirements.txt" conda_yml = "conda.yml" setup_cfg = "setup.cfg" diff --git a/dparse/parser.py b/dparse/parser.py index f7becd8..f200607 100644 --- a/dparse/parser.py +++ b/dparse/parser.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals, absolute_import - import os from collections import OrderedDict import re @@ -80,7 +77,7 @@ def yield_lines(strs): yield PackagingRequirement(line) -class RequirementsTXTLineParser(object): +class RequirementsTXTLineParser: """ """ @@ -112,7 +109,7 @@ def parse(cls, line): return dep -class Parser(object): +class Parser: """ """ @@ -132,8 +129,7 @@ def iter_lines(self, lineno=0): :param lineno: :return: """ - for line in self.lines[lineno:]: - yield line + yield from self.lines[lineno:] @property def lines(self): @@ -241,7 +237,7 @@ def parse(self): req_file_path = self.resolve_file(self.obj.path, line) if self.resolve and os.path.exists(req_file_path): - with open(req_file_path, 'r') as f: + with open(req_file_path) as f: content = f.read() dep_file = DependencyFile( diff --git a/dparse/regex.py b/dparse/regex.py index 4a1204e..751a254 100644 --- a/dparse/regex.py +++ b/dparse/regex.py @@ -1,4 +1 @@ -# -*- coding: utf-8 -*- -from __future__ import absolute_import, print_function, unicode_literals - HASH_REGEX = r"--hash[=| ]\w+:\w+" diff --git a/dparse/updater.py b/dparse/updater.py index 3239ee4..8b29573 100644 --- a/dparse/updater.py +++ b/dparse/updater.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- -from __future__ import absolute_import, print_function, unicode_literals import re import json import tempfile @@ -12,7 +10,7 @@ import tomli as tomllib -class RequirementsTXTUpdater(object): +class RequirementsTXTUpdater: SUB_REGEX = r"^{}(?=\s*\r?\n?$)" @classmethod @@ -81,7 +79,7 @@ class SetupCFGUpdater(CondaYMLUpdater): pass -class PipfileUpdater(object): +class PipfileUpdater: @classmethod def update(cls, content, dependency, version, spec="==", hashes=()): data = tomllib.loads(content) @@ -107,7 +105,7 @@ def update(cls, content, dependency, version, spec="==", hashes=()): return data -class PipfileLockUpdater(object): +class PipfileLockUpdater: @classmethod def update(cls, content, dependency, version, spec="==", hashes=()): data = json.loads(content) diff --git a/tests/__init__.py b/tests/__init__.py index a846e5b..c73d0ac 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,3 +1 @@ -# -*- coding: utf-8 -*- - """Unit test package for dparse.""" diff --git a/tests/test_dependencies.py b/tests/test_dependencies.py index a5bb924..480618f 100644 --- a/tests/test_dependencies.py +++ b/tests/test_dependencies.py @@ -1,6 +1,4 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -from __future__ import unicode_literals, absolute_import """Tests for `dparse.dependencies`""" import pytest diff --git a/tests/test_parse.py b/tests/test_parse.py index 2d6a2dd..2f5aa9d 100644 --- a/tests/test_parse.py +++ b/tests/test_parse.py @@ -1,6 +1,4 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- -from __future__ import unicode_literals import sys from pathlib import PurePath diff --git a/tests/test_updater.py b/tests/test_updater.py index 541f77d..d7340da 100644 --- a/tests/test_updater.py +++ b/tests/test_updater.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- """Tests for `dparse.updater`"""