From 503381e6f58d7c19d0f1ea3add18286ae7ffabb6 Mon Sep 17 00:00:00 2001 From: Eisuke Kawashima Date: Thu, 3 Nov 2022 18:01:31 +0900 Subject: [PATCH 1/3] fix: [E401](https://github.com/PyCQA/pycodestyle/blob/2.9.1/docs/intro.rst#error-codes) --- examples/yaml-highlight/yaml_hl.py | 6 +++++- lib/yaml/constructor.py | 8 +++++++- lib/yaml/reader.py | 3 ++- lib/yaml/representer.py | 6 +++++- setup.py | 9 ++++++++- tests/legacy_tests/canonical.py | 5 ++++- tests/legacy_tests/test_all.py | 4 +++- tests/legacy_tests/test_appliance.py | 8 +++++++- tests/legacy_tests/test_build.py | 7 +++++-- tests/legacy_tests/test_build_ext.py | 7 +++++-- tests/legacy_tests/test_canonical.py | 3 ++- tests/legacy_tests/test_constructor.py | 3 ++- tests/legacy_tests/test_errors.py | 3 ++- tests/legacy_tests/test_input_output.py | 6 +++++- tests/legacy_tests/test_structure.py | 3 ++- tests/legacy_tests/test_yaml_ext.py | 20 ++++++++++++++++---- 16 files changed, 80 insertions(+), 21 deletions(-) diff --git a/examples/yaml-highlight/yaml_hl.py b/examples/yaml-highlight/yaml_hl.py index 96e0ae7b..d0bb5e37 100755 --- a/examples/yaml-highlight/yaml_hl.py +++ b/examples/yaml-highlight/yaml_hl.py @@ -1,6 +1,10 @@ #!/usr/bin/python -import yaml, codecs, sys, os.path, optparse +import yaml +import codecs +import sys +import os.path +import optparse class Style: diff --git a/lib/yaml/constructor.py b/lib/yaml/constructor.py index 619acd30..e335e1f0 100644 --- a/lib/yaml/constructor.py +++ b/lib/yaml/constructor.py @@ -11,7 +11,13 @@ from .error import * from .nodes import * -import collections.abc, datetime, base64, binascii, re, sys, types +import collections.abc +import datetime +import base64 +import binascii +import re +import sys +import types class ConstructorError(MarkedYAMLError): pass diff --git a/lib/yaml/reader.py b/lib/yaml/reader.py index 774b0219..3868b4df 100644 --- a/lib/yaml/reader.py +++ b/lib/yaml/reader.py @@ -19,7 +19,8 @@ from .error import YAMLError, Mark -import codecs, re +import codecs +import re class ReaderError(YAMLError): diff --git a/lib/yaml/representer.py b/lib/yaml/representer.py index 808ca06d..9d34c0d7 100644 --- a/lib/yaml/representer.py +++ b/lib/yaml/representer.py @@ -5,7 +5,11 @@ from .error import * from .nodes import * -import datetime, copyreg, types, base64, collections +import datetime +import copyreg +import types +import base64 +import collections class RepresenterError(YAMLError): pass diff --git a/setup.py b/setup.py index 8040320f..95f0c607 100644 --- a/setup.py +++ b/setup.py @@ -65,7 +65,14 @@ """ -import sys, os, os.path, pathlib, platform, shutil, tempfile, warnings +import sys +import os +import os.path +import pathlib +import platform +import shutil +import tempfile +import warnings # for newer setuptools, enable the embedded distutils before importing setuptools/distutils to avoid warnings os.environ['SETUPTOOLS_USE_DISTUTILS'] = 'local' diff --git a/tests/legacy_tests/canonical.py b/tests/legacy_tests/canonical.py index a8b4e3a7..e982bbb8 100644 --- a/tests/legacy_tests/canonical.py +++ b/tests/legacy_tests/canonical.py @@ -1,5 +1,8 @@ -import yaml, yaml.composer, yaml.constructor, yaml.resolver +import yaml +import yaml.composer +import yaml.constructor +import yaml.resolver class CanonicalError(yaml.YAMLError): pass diff --git a/tests/legacy_tests/test_all.py b/tests/legacy_tests/test_all.py index 72a50676..b674c19e 100644 --- a/tests/legacy_tests/test_all.py +++ b/tests/legacy_tests/test_all.py @@ -1,5 +1,7 @@ -import sys, yaml, test_appliance +import sys +import yaml +import test_appliance def main(args=None): collections = [] diff --git a/tests/legacy_tests/test_appliance.py b/tests/legacy_tests/test_appliance.py index 7f8a0a79..9ffb1690 100644 --- a/tests/legacy_tests/test_appliance.py +++ b/tests/legacy_tests/test_appliance.py @@ -1,5 +1,11 @@ -import sys, os, os.path, types, traceback, pprint, pathlib +import sys +import os +import os.path +import types +import traceback +import pathlib +import pprint DATA = str(pathlib.Path(__file__).parent / 'data') diff --git a/tests/legacy_tests/test_build.py b/tests/legacy_tests/test_build.py index df3f943b..b95afccb 100644 --- a/tests/legacy_tests/test_build.py +++ b/tests/legacy_tests/test_build.py @@ -1,10 +1,13 @@ if __name__ == '__main__': - import sys, os, distutils.util + import sys + import os + import distutils.util build_lib = 'build/lib' build_lib_ext = os.path.join('build', 'lib.{}-{}.{}'.format(distutils.util.get_platform(), *sys.version_info)) sys.path.insert(0, build_lib) sys.path.insert(0, build_lib_ext) - import test_yaml, test_appliance + import test_yaml + import test_appliance test_appliance.run(test_yaml) diff --git a/tests/legacy_tests/test_build_ext.py b/tests/legacy_tests/test_build_ext.py index fa843f6e..830454d7 100644 --- a/tests/legacy_tests/test_build_ext.py +++ b/tests/legacy_tests/test_build_ext.py @@ -1,11 +1,14 @@ if __name__ == '__main__': - import sys, os, distutils.util + import sys + import os + import distutils.util build_lib = 'build/lib' build_lib_ext = os.path.join('build', 'lib.{}-{}.{}'.format(distutils.util.get_platform(), *sys.version_info)) sys.path.insert(0, build_lib) sys.path.insert(0, build_lib_ext) - import test_yaml_ext, test_appliance + import test_yaml_ext + import test_appliance test_appliance.run(test_yaml_ext) diff --git a/tests/legacy_tests/test_canonical.py b/tests/legacy_tests/test_canonical.py index 7bded817..2d3a0e53 100644 --- a/tests/legacy_tests/test_canonical.py +++ b/tests/legacy_tests/test_canonical.py @@ -1,5 +1,6 @@ -import yaml, canonical +import yaml +import canonical def test_canonical_scanner(canonical_filename, verbose=False): with open(canonical_filename, 'rb') as file: diff --git a/tests/legacy_tests/test_constructor.py b/tests/legacy_tests/test_constructor.py index 0783a21b..adcbb5cf 100644 --- a/tests/legacy_tests/test_constructor.py +++ b/tests/legacy_tests/test_constructor.py @@ -297,7 +297,8 @@ def test_subclass_blacklist_types(data_filename, verbose=False): test_subclass_blacklist_types.unittest = ['.subclass_blacklist'] if __name__ == '__main__': - import sys, test_constructor + import sys + import test_constructor sys.modules['test_constructor'] = sys.modules['__main__'] import test_appliance test_appliance.run(globals()) diff --git a/tests/legacy_tests/test_errors.py b/tests/legacy_tests/test_errors.py index 45f233f3..9f197866 100644 --- a/tests/legacy_tests/test_errors.py +++ b/tests/legacy_tests/test_errors.py @@ -1,5 +1,6 @@ -import yaml, test_emitter +import yaml +import test_emitter def test_loader_error(error_filename, verbose=False): try: diff --git a/tests/legacy_tests/test_input_output.py b/tests/legacy_tests/test_input_output.py index 6d82c0db..3496da93 100644 --- a/tests/legacy_tests/test_input_output.py +++ b/tests/legacy_tests/test_input_output.py @@ -1,6 +1,10 @@ import yaml -import codecs, io, tempfile, os, os.path +import codecs +import io +import tempfile +import os +import os.path def test_unicode_input(unicode_filename, verbose=False): with open(unicode_filename, 'rb') as file: diff --git a/tests/legacy_tests/test_structure.py b/tests/legacy_tests/test_structure.py index cbd4c3e0..4f3e43ae 100644 --- a/tests/legacy_tests/test_structure.py +++ b/tests/legacy_tests/test_structure.py @@ -1,5 +1,6 @@ -import yaml, canonical +import yaml +import canonical import pprint def _convert_structure(loader): diff --git a/tests/legacy_tests/test_yaml_ext.py b/tests/legacy_tests/test_yaml_ext.py index a2ccb2f2..f7ff3800 100644 --- a/tests/legacy_tests/test_yaml_ext.py +++ b/tests/legacy_tests/test_yaml_ext.py @@ -1,5 +1,10 @@ -import yaml._yaml, yaml -import types, pprint, tempfile, sys, os +import yaml +import yaml._yaml +import types +import pprint +import tempfile +import sys +import os yaml.PyBaseLoader = yaml.BaseLoader yaml.PySafeLoader = yaml.SafeLoader @@ -282,8 +287,15 @@ def wrap_ext(collections): assert function.__name__ not in globals() globals()[function.__name__] = function -import test_tokens, test_structure, test_errors, test_resolver, test_constructor, \ - test_emitter, test_representer, test_recursive, test_input_output +import test_tokens +import test_structure +import test_errors +import test_resolver +import test_constructor +import test_emitter +import test_representer +import test_recursive +import test_input_output wrap_ext([test_tokens, test_structure, test_errors, test_resolver, test_constructor, test_emitter, test_representer, test_recursive, test_input_output]) From ab27a0aafb6d4be69b05b2bbba30848418f4ab80 Mon Sep 17 00:00:00 2001 From: Eisuke Kawashima Date: Thu, 3 Nov 2022 18:07:18 +0900 Subject: [PATCH 2/3] fix: [E713](https://github.com/PyCQA/pycodestyle/blob/2.9.1/docs/intro.rst#error-codes) --- lib/yaml/constructor.py | 4 ++-- lib/yaml/representer.py | 4 ++-- lib/yaml/resolver.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/yaml/constructor.py b/lib/yaml/constructor.py index e335e1f0..8949d475 100644 --- a/lib/yaml/constructor.py +++ b/lib/yaml/constructor.py @@ -164,13 +164,13 @@ def construct_pairs(self, node, deep=False): @classmethod def add_constructor(cls, tag, constructor): - if not 'yaml_constructors' in cls.__dict__: + if 'yaml_constructors' not in cls.__dict__: cls.yaml_constructors = cls.yaml_constructors.copy() cls.yaml_constructors[tag] = constructor @classmethod def add_multi_constructor(cls, tag_prefix, multi_constructor): - if not 'yaml_multi_constructors' in cls.__dict__: + if 'yaml_multi_constructors' not in cls.__dict__: cls.yaml_multi_constructors = cls.yaml_multi_constructors.copy() cls.yaml_multi_constructors[tag_prefix] = multi_constructor diff --git a/lib/yaml/representer.py b/lib/yaml/representer.py index 9d34c0d7..fd13479e 100644 --- a/lib/yaml/representer.py +++ b/lib/yaml/representer.py @@ -68,13 +68,13 @@ def represent_data(self, data): @classmethod def add_representer(cls, data_type, representer): - if not 'yaml_representers' in cls.__dict__: + if 'yaml_representers' not in cls.__dict__: cls.yaml_representers = cls.yaml_representers.copy() cls.yaml_representers[data_type] = representer @classmethod def add_multi_representer(cls, data_type, representer): - if not 'yaml_multi_representers' in cls.__dict__: + if 'yaml_multi_representers' not in cls.__dict__: cls.yaml_multi_representers = cls.yaml_multi_representers.copy() cls.yaml_multi_representers[data_type] = representer diff --git a/lib/yaml/resolver.py b/lib/yaml/resolver.py index 3522bdaa..a7802a75 100644 --- a/lib/yaml/resolver.py +++ b/lib/yaml/resolver.py @@ -24,7 +24,7 @@ def __init__(self): @classmethod def add_implicit_resolver(cls, tag, regexp, first): - if not 'yaml_implicit_resolvers' in cls.__dict__: + if 'yaml_implicit_resolvers' not in cls.__dict__: implicit_resolvers = {} for key in cls.yaml_implicit_resolvers: implicit_resolvers[key] = cls.yaml_implicit_resolvers[key][:] @@ -48,7 +48,7 @@ def add_path_resolver(cls, tag, path, kind=None): # a mapping value that corresponds to a scalar key which content is # equal to the `index_check` value. An integer `index_check` matches # against a sequence value with the index equal to `index_check`. - if not 'yaml_path_resolvers' in cls.__dict__: + if 'yaml_path_resolvers' not in cls.__dict__: cls.yaml_path_resolvers = cls.yaml_path_resolvers.copy() new_path = [] for element in path: From e59ad9517c987bf7c83d988364e54e069492c6a8 Mon Sep 17 00:00:00 2001 From: Eisuke Kawashima Date: Thu, 3 Nov 2022 18:00:04 +0900 Subject: [PATCH 3/3] fix: [E722](https://github.com/PyCQA/pycodestyle/blob/2.9.1/docs/intro.rst#error-codes) --- tests/legacy_tests/test_constructor.py | 2 +- tests/legacy_tests/test_multi_constructor.py | 4 ++-- tests/legacy_tests/test_schema.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/legacy_tests/test_constructor.py b/tests/legacy_tests/test_constructor.py index adcbb5cf..cc76a403 100644 --- a/tests/legacy_tests/test_constructor.py +++ b/tests/legacy_tests/test_constructor.py @@ -47,7 +47,7 @@ def my_time_constructor(constructor, node): tz = None try: tz = dt.tzinfo.tzname(dt) - except: + except Exception: pass return [dt, tz] diff --git a/tests/legacy_tests/test_multi_constructor.py b/tests/legacy_tests/test_multi_constructor.py index dcff2ce5..00060cbb 100644 --- a/tests/legacy_tests/test_multi_constructor.py +++ b/tests/legacy_tests/test_multi_constructor.py @@ -14,10 +14,10 @@ def myconstructor2(constructor, tag, node): string = '' try: i = tag.index('!') + 1 - except: + except Exception: try: i = tag.rindex(':') + 1 - except: + except Exception: pass if i >= 0: tag = tag[i:] diff --git a/tests/legacy_tests/test_schema.py b/tests/legacy_tests/test_schema.py index f3370ec1..0ce6574f 100644 --- a/tests/legacy_tests/test_schema.py +++ b/tests/legacy_tests/test_schema.py @@ -85,7 +85,7 @@ def test_implicit_resolver(data_filename, skip_filename, verbose=False): # Test loading try: loaded = yaml.safe_load(input) - except: + except Exception: print("Error:", sys.exc_info()[0], '(', sys.exc_info()[1], ')') fail+=1 _fail(input, test)