mirror of https://github.com/pallets/flask.git
_compat.py: Use feature detection instead of version detection
When run on Python 3, linters such as Pylint and Flake8 will correctly flag __unicode__ and __long__ as _undefined names_ because _compat.py does not currently follow the Python porting best practice [___use feature detection instead of version detection___](https://docs.python.org/3/howto/pyporting.html#use-feature-detection-instead-of-version-detection). This PR allows this project to pass those tests without adding any linter directives.
This commit is contained in:
parent
74691fbe01
commit
47bdf9f26f
|
|
@ -16,12 +16,16 @@ import sys
|
|||
PY2 = sys.version_info[0] == 2
|
||||
_identity = lambda x: x
|
||||
|
||||
|
||||
if not PY2:
|
||||
try: # Python 2
|
||||
text_type = unicode
|
||||
string_types = (str, unicode)
|
||||
integer_types = (int, long)
|
||||
except NameError: # Python 3
|
||||
text_type = str
|
||||
string_types = (str,)
|
||||
integer_types = (int,)
|
||||
|
||||
if not PY2:
|
||||
iterkeys = lambda d: iter(d.keys())
|
||||
itervalues = lambda d: iter(d.values())
|
||||
iteritems = lambda d: iter(d.items())
|
||||
|
|
@ -38,10 +42,6 @@ if not PY2:
|
|||
implements_to_string = _identity
|
||||
|
||||
else:
|
||||
text_type = unicode
|
||||
string_types = (str, unicode)
|
||||
integer_types = (int, long)
|
||||
|
||||
iterkeys = lambda d: d.iterkeys()
|
||||
itervalues = lambda d: d.itervalues()
|
||||
iteritems = lambda d: d.iteritems()
|
||||
|
|
|
|||
Loading…
Reference in New Issue