diff --git a/confuse/__init__.py b/confuse/__init__.py index ffc8f90..0e7bfd3 100644 --- a/confuse/__init__.py +++ b/confuse/__init__.py @@ -1,8 +1,6 @@ """Painless YAML configuration. """ -from __future__ import division, absolute_import, print_function - __version__ = '2.0.0' from .exceptions import * # NOQA diff --git a/confuse/core.py b/confuse/core.py index 6c6c4b0..7d00d9c 100644 --- a/confuse/core.py +++ b/confuse/core.py @@ -15,8 +15,6 @@ """Worry-free YAML configuration files. """ -from __future__ import division, absolute_import, print_function - import errno import os import yaml @@ -165,23 +163,10 @@ def set_args(self, namespace, dots=False): def __str__(self): """Get the value for this view as a bytestring. """ - if util.PY3: - return self.__unicode__() - else: - return bytes(self.get()) - - def __unicode__(self): - """Get the value for this view as a Unicode string. - """ - return util.STRING(self.get()) - - def __nonzero__(self): - """Gets the value for this view as a boolean. (Python 2 only.) - """ - return self.__bool__() + return str(self.get()) def __bool__(self): - """Gets the value for this view as a boolean. (Python 3 only.) + """Gets the value for this view as a bool. """ return bool(self.get()) @@ -441,7 +426,7 @@ def __init__(self, parent, key): self.name += u'#{0}'.format(self.key) elif isinstance(self.key, bytes): self.name += self.key.decode('utf-8') - elif isinstance(self.key, util.STRING): + elif isinstance(self.key, str): self.name += self.key else: self.name += repr(self.key) diff --git a/confuse/exceptions.py b/confuse/exceptions.py index 782260e..c277dd0 100644 --- a/confuse/exceptions.py +++ b/confuse/exceptions.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - import yaml __all__ = [ diff --git a/confuse/sources.py b/confuse/sources.py index 2b0f53b..ed0c5f4 100644 --- a/confuse/sources.py +++ b/confuse/sources.py @@ -1,6 +1,4 @@ -from __future__ import division, absolute_import, print_function - -from .util import BASESTRING, build_dict +from .util import build_dict from . import yaml_util import os @@ -27,8 +25,7 @@ def __init__(self, value, filename=None, default=False, behavior. """ super(ConfigSource, self).__init__(value) - if (filename is not None - and not isinstance(filename, BASESTRING)): + if filename is not None and not isinstance(filename, str): raise TypeError(u'filename must be a string or None') self.filename = filename self.default = default diff --git a/confuse/templates.py b/confuse/templates.py index 1b56b28..a46b57a 100644 --- a/confuse/templates.py +++ b/confuse/templates.py @@ -1,29 +1,12 @@ -from __future__ import division, absolute_import, print_function - import os import re -import sys +import enum +import pathlib +from collections import abc from . import util from . import exceptions -try: - import enum - SUPPORTS_ENUM = True -except ImportError: - SUPPORTS_ENUM = False - -try: - import pathlib - SUPPORTS_PATHLIB = True -except ImportError: - SUPPORTS_PATHLIB = False - -if sys.version_info >= (3, 3): - from collections import abc -else: - import collections as abc - REQUIRED = object() """A sentinel indicating that there is no default value and an exception @@ -130,7 +113,7 @@ class Number(Template): def convert(self, value, view): """Check that the value is an int or a float. """ - if isinstance(value, util.NUMERIC_TYPES): + if isinstance(value, (int, float)): return value else: self.fail( @@ -243,7 +226,7 @@ def __repr__(self): def convert(self, value, view): """Check that the value is a string and matches the pattern. """ - if not isinstance(value, util.BASESTRING): + if not isinstance(value, str): self.fail(u'must be a string', view, True) if self.pattern and not self.regex.match(value): @@ -278,7 +261,7 @@ def convert(self, value, view): """Ensure that the value is among the choices (and remap if the choices are a mapping). """ - if (SUPPORTS_ENUM and isinstance(self.choices, type) + if (isinstance(self.choices, type) and issubclass(self.choices, enum.Enum)): try: return self.choices(value) @@ -385,7 +368,7 @@ def __init__(self, split=True, default=REQUIRED): self.split = split def _convert_value(self, x, view): - if isinstance(x, util.STRING): + if isinstance(x, str): return x elif isinstance(x, bytes): return x.decode('utf-8', 'ignore') @@ -396,7 +379,7 @@ def convert(self, value, view): if isinstance(value, bytes): value = value.decode('utf-8', 'ignore') - if isinstance(value, util.STRING): + if isinstance(value, str): if self.split: value = value.split() else: @@ -566,13 +549,13 @@ def value(self, view, template=None): except exceptions.NotFoundError: return self.get_default_value(view.name) - if not isinstance(path, util.BASESTRING): + if not isinstance(path, str): self.fail( u'must be a filename, not {0}'.format(type(path).__name__), view, True ) - path = os.path.expanduser(util.STRING(path)) + path = os.path.expanduser(str(path)) if not os.path.isabs(path): if self.cwd is not None: @@ -602,9 +585,6 @@ class Path(Filename): Filenames are parsed equivalent to the `Filename` template and then converted to `pathlib.Path` objects. - - For Python 2 it returns the original path as returned by the `Filename` - template. """ def value(self, view, template=None): value = super(Path, self).value(view, template) @@ -709,15 +689,14 @@ def as_template(value): return Integer() elif isinstance(value, int): return Integer(value) - elif isinstance(value, type) and issubclass(value, util.BASESTRING): + elif isinstance(value, type) and issubclass(value, str): return String() - elif isinstance(value, util.BASESTRING): + elif isinstance(value, str): return String(value) elif isinstance(value, set): # convert to list to avoid hash related problems return Choice(list(value)) - elif (SUPPORTS_ENUM and isinstance(value, type) - and issubclass(value, enum.Enum)): + elif isinstance(value, type) and issubclass(value, enum.Enum): return Choice(value) elif isinstance(value, list): return OneOf(value) @@ -725,7 +704,7 @@ def as_template(value): return Number() elif isinstance(value, float): return Number(value) - elif SUPPORTS_PATHLIB and isinstance(value, pathlib.PurePath): + elif isinstance(value, pathlib.PurePath): return Path(value) elif value is None: return Template(None) diff --git a/confuse/util.py b/confuse/util.py index 70bd456..c27e161 100644 --- a/confuse/util.py +++ b/confuse/util.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - import os import sys import argparse @@ -8,12 +6,6 @@ import pkgutil -PY3 = sys.version_info[0] == 3 -STRING = str if PY3 else unicode # noqa: F821 -BASESTRING = str if PY3 else basestring # noqa: F821 -NUMERIC_TYPES = (int, float) if PY3 else (int, float, long) # noqa: F821 - - UNIX_DIR_FALLBACK = '~/.config' WINDOWS_DIR_VAR = 'APPDATA' WINDOWS_DIR_FALLBACK = '~\\AppData\\Roaming' @@ -75,7 +67,7 @@ def build_dict(obj, sep='', keep_none=False): return obj # Get keys iterator - keys = obj.keys() if PY3 else obj.iterkeys() + keys = obj.keys() if sep: # Splitting keys by `sep` needs sorted keys to prevent parents # from clobbering children diff --git a/confuse/yaml_util.py b/confuse/yaml_util.py index 2cb4b52..de12d45 100644 --- a/confuse/yaml_util.py +++ b/confuse/yaml_util.py @@ -1,9 +1,6 @@ -from __future__ import division, absolute_import, print_function - from collections import OrderedDict import yaml from .exceptions import ConfigReadError -from .util import BASESTRING # YAML loading. @@ -119,7 +116,7 @@ def parse_as_scalar(value, loader=Loader): - The empty string '' will return None """ # We only deal with strings - if not isinstance(value, BASESTRING): + if not isinstance(value, str): return value try: loader = loader('') diff --git a/example/__init__.py b/example/__init__.py index 0363e3c..ad44a03 100644 --- a/example/__init__.py +++ b/example/__init__.py @@ -1,5 +1,4 @@ """An example application using Confuse for configuration.""" -from __future__ import division, absolute_import, print_function import confuse import argparse diff --git a/setup.cfg b/setup.cfg index 9350912..00f2bd8 100644 --- a/setup.cfg +++ b/setup.cfg @@ -10,13 +10,6 @@ min-version=3.6 # - E221: multiple spaces before operator (used to align visually) # - E731: do not assign a lambda expression, use a def # - C901: function/method complexity -# `flake8-future-import` errors we ignore: -# - FI50: `__future__` import "division" present -# - FI51: `__future__` import "absolute_import" present -# - FI12: `__future__` import "with_statement" missing -# - FI53: `__future__` import "print_function" present -# - FI14: `__future__` import "unicode_literals" missing -# - FI15: `__future__` import "generator_stop" missing # pycodestyle warnings ignored: # - W503: line breaks before binary operators -ignore=C901,E241,E221,E731,FI50,FI51,FI12,FI53,FI14,FI15,W503 +ignore=C901,E241,E221,E731,W503 diff --git a/test/__init__.py b/test/__init__.py index 7d0317e..cebf5c4 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - import confuse import tempfile import shutil diff --git a/test/test_cli.py b/test/test_cli.py index 3b7153b..72b861c 100644 --- a/test/test_cli.py +++ b/test/test_cli.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - import confuse import argparse from argparse import Namespace diff --git a/test/test_dump.py b/test/test_dump.py index e40add7..743b907 100644 --- a/test/test_dump.py +++ b/test/test_dump.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - import confuse import textwrap import unittest diff --git a/test/test_env.py b/test/test_env.py index f44f03a..cd8fe85 100644 --- a/test/test_env.py +++ b/test/test_env.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - import confuse import os import unittest diff --git a/test/test_paths.py b/test/test_paths.py index 5333611..d4c53d2 100644 --- a/test/test_paths.py +++ b/test/test_paths.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - import confuse import confuse.yaml_util import ntpath diff --git a/test/test_utils.py b/test/test_utils.py index 2085bad..b8ebc9c 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - from argparse import Namespace from collections import OrderedDict import confuse diff --git a/test/test_valid.py b/test/test_valid.py index b5a8741..daa78c0 100644 --- a/test/test_valid.py +++ b/test/test_valid.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - try: import enum SUPPORTS_ENUM = True @@ -115,18 +113,6 @@ def test_concrete_string_as_template(self): self.assertIsInstance(typ, confuse.String) self.assertEqual(typ.default, 'foo') - @unittest.skipIf(confuse.PY3, "unicode only present in Python 2") - def test_unicode_type_as_template(self): - typ = confuse.as_template(unicode) # noqa ignore=F821 - self.assertIsInstance(typ, confuse.String) - self.assertEqual(typ.default, confuse.REQUIRED) - - @unittest.skipIf(confuse.PY3, "basestring only present in Python 2") - def test_basestring_as_template(self): - typ = confuse.as_template(basestring) # noqa ignore=F821 - self.assertIsInstance(typ, confuse.String) - self.assertEqual(typ.default, confuse.REQUIRED) - def test_dict_as_template(self): typ = confuse.as_template({'key': 9}) self.assertIsInstance(typ, confuse.MappingTemplate) diff --git a/test/test_validation.py b/test/test_validation.py index 017c47c..e1f314c 100644 --- a/test/test_validation.py +++ b/test/test_validation.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - try: import enum SUPPORTS_ENUM = True @@ -121,11 +119,6 @@ def test_as_number_int(self): config = _root({'i': 2}) config['i'].as_number() - @unittest.skipIf(confuse.PY3, "long only present in Python 2") - def test_as_number_long_in_py2(self): - config = _root({'l': long(3)}) # noqa ignore=F821 - config['l'].as_number() - def test_as_number_string(self): config = _root({'s': 'a'}) with self.assertRaises(confuse.ConfigTypeError): diff --git a/test/test_views.py b/test/test_views.py index e98eb97..32f73ca 100644 --- a/test/test_views.py +++ b/test/test_views.py @@ -1,12 +1,7 @@ -from __future__ import division, absolute_import, print_function - import confuse -import sys import unittest from . import _root -PY3 = sys.version_info[0] == 3 - class SingleSourceTest(unittest.TestCase): def test_dict_access(self): @@ -101,12 +96,6 @@ def test_str_conversion_from_int(self): value = str(config['foo']) self.assertEqual(value, '2') - @unittest.skipIf(confuse.PY3, "unicode only present in Python 2") - def test_unicode_conversion_from_int(self): - config = _root({'foo': 2}) - value = unicode(config['foo']) # noqa ignore=F821 - self.assertEqual(value, unicode('2')) # noqa ignore=F821 - def test_bool_conversion_from_bool(self): config = _root({'foo': True}) value = bool(config['foo']) diff --git a/test/test_yaml.py b/test/test_yaml.py index da8ab36..ccb6b30 100644 --- a/test/test_yaml.py +++ b/test/test_yaml.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - import confuse import yaml import unittest diff --git a/tox.ini b/tox.ini index e82806c..9e42ab1 100644 --- a/tox.ini +++ b/tox.ini @@ -20,7 +20,6 @@ deps = [_flake8] deps = flake8 - flake8-future-import pep8-naming files = example confuse test docs