[vlc-commits] Define basestring, unicode using feature detection

cclauss git at videolan.org
Fri Jul 13 12:00:57 CEST 2018


vlc/python | branch: master | cclauss <cclauss at bluewin.ch> | Tue Jul 10 17:00:57 2018 +0200| [a08b71dbaa3032e298a964778f53179fc8794833] | committer: GitHub

Define basestring, unicode using feature detection

Use 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) to define basestring() and unicode() in order to placate flake8.

> http://git.videolan.org/gitweb.cgi/vlc/python.git/?a=commit;h=a08b71dbaa3032e298a964778f53179fc8794833
---

 generator/generate.py | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/generator/generate.py b/generator/generate.py
index e274376..5bf4b22 100755
--- a/generator/generate.py
+++ b/generator/generate.py
@@ -72,22 +72,28 @@ import time
 BASEDIR = os.path.abspath(os.path.dirname(__file__))
 TEMPLATEDIR = os.path.join(BASEDIR, 'templates')
 
+str = str
+
+try:
+    basestring = basestring    # Python 2
+except NameError:
+    basestring = (str, bytes)  # Python 3
+
+try:
+    unicode = unicode          # Python 2
+except NameError:
+    unicode = str              # Python 3
+
 if sys.version_info[0] < 3:
     PYTHON3 = False
+    bytes = str
     def opener(name, mode='r'):
         return open(name, mode)
-    str = str
-    unicode = unicode
-    bytes = str
-    basestring = basestring
 else:  # Python 3+
     PYTHON3 = True
+    bytes = bytes
     def opener(name, mode='r'):  #PYCHOK expected
         return open(name, mode, encoding='utf8')
-    str = str
-    unicode = str
-    bytes = bytes
-    basestring = (str, bytes)
 
 # Functions not wrapped/not referenced
 _blacklist = {



More information about the vlc-commits mailing list