Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PEP8 fixes #677

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion examples/yaml-highlight/yaml_hl.py
Original file line number Diff line number Diff line change
@@ -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:

Expand Down
12 changes: 9 additions & 3 deletions lib/yaml/constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -158,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

Expand Down
3 changes: 2 additions & 1 deletion lib/yaml/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

from .error import YAMLError, Mark

import codecs, re
import codecs
import re

class ReaderError(YAMLError):

Expand Down
10 changes: 7 additions & 3 deletions lib/yaml/representer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -64,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

Expand Down
4 changes: 2 additions & 2 deletions lib/yaml/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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][:]
Expand All @@ -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:
Expand Down
9 changes: 8 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
5 changes: 4 additions & 1 deletion tests/legacy_tests/canonical.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 3 additions & 1 deletion tests/legacy_tests/test_all.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@

import sys, yaml, test_appliance
import sys
import yaml
import test_appliance

def main(args=None):
collections = []
Expand Down
8 changes: 7 additions & 1 deletion tests/legacy_tests/test_appliance.py
Original file line number Diff line number Diff line change
@@ -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')

Expand Down
7 changes: 5 additions & 2 deletions tests/legacy_tests/test_build.py
Original file line number Diff line number Diff line change
@@ -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)

7 changes: 5 additions & 2 deletions tests/legacy_tests/test_build_ext.py
Original file line number Diff line number Diff line change
@@ -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)

3 changes: 2 additions & 1 deletion tests/legacy_tests/test_canonical.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
5 changes: 3 additions & 2 deletions tests/legacy_tests/test_constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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())
Expand Down
3 changes: 2 additions & 1 deletion tests/legacy_tests/test_errors.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import yaml, test_emitter
import yaml
import test_emitter

def test_loader_error(error_filename, verbose=False):
try:
Expand Down
6 changes: 5 additions & 1 deletion tests/legacy_tests/test_input_output.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
4 changes: 2 additions & 2 deletions tests/legacy_tests/test_multi_constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:]
Expand Down
2 changes: 1 addition & 1 deletion tests/legacy_tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion tests/legacy_tests/test_structure.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import yaml, canonical
import yaml
import canonical
import pprint

def _convert_structure(loader):
Expand Down
20 changes: 16 additions & 4 deletions tests/legacy_tests/test_yaml_ext.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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])

Expand Down