Skip to content
Myr

_compat.py: Use feature detection instead of version detection

Before adoption: this commit came in with the history the project adopted, so no landing records it.

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.

authored by cclauss · committed by GitHub · parent 74691fb · Browse files · 1 file+6 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+6 added−6 removed

  • other:+6 added−6 removed

1 file+6 added−6 removed

modified:flask/_compat.py+6 added-6 removed
14 unmodified lines
1516PY2 = sys.version_info[0] == 217_identity = lambda x: x181920if not PY2:19try: # Python 220 text_type = unicode21 string_types = (str, unicode)22 integer_types = (int, long)23except NameError: # Python 324 text_type = str25 string_types = (str,)26 integer_types = (int,)2728if not PY2:29 iterkeys = lambda d: iter(d.keys())30 itervalues = lambda d: iter(d.values())31 iteritems = lambda d: iter(d.items())32
8 unmodified lines
4142 implements_to_string = _identity4344else:41 text_type = unicode42 string_types = (str, unicode)43 integer_types = (int, long)4445 iterkeys = lambda d: d.iterkeys()46 itervalues = lambda d: d.itervalues()47 iteritems = lambda d: d.iteritems()48
62 unmodified lines