Skip to content

Commit

Permalink
global: use Python feature detection in _compat.py
Browse files Browse the repository at this point in the history
* BETTER Python porting best practice use feature detection instead
  of version detection to save an import and pass both PyLint
  and Flake8 tests with neither 'pragma' nor 'noqa'.
  • Loading branch information
cclauss authored and jirikuncar committed May 10, 2018
1 parent 025d398 commit f8dc205
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions dictdiffer/_compat.py
Expand Up @@ -8,23 +8,22 @@

"""Python compatibility definitions."""

import sys

if sys.version_info[0] == 3: # pragma: no cover (Python 2/3 specific code)
try:
PY2 = True
string_types = basestring,
text_type = unicode
num_types = int, long, float
except NameError:
PY2 = False
string_types = str,
text_type = str
num_types = int, float
PY2 = False

if PY2:
from collections import MutableMapping, MutableSet, MutableSequence
from itertools import izip_longest as _zip_longest
else:
from collections.abc import MutableMapping, MutableSet, MutableSequence
from itertools import zip_longest as _zip_longest
izip_longest = _zip_longest
else: # pragma: no cover (Python 2/3 specific code)
string_types = basestring,
text_type = unicode
num_types = int, long, float
PY2 = True

from collections import MutableMapping, MutableSet, MutableSequence
from itertools import izip_longest as _zip_longest
izip_longest = _zip_longest
izip_longest = _zip_longest

0 comments on commit f8dc205

Please sign in to comment.