[utils] Avoid comparing `type(var)`, etc, to pass new Linter rules
authordirkf <fieldhouse@gmx.net>
Sun, 30 Jul 2023 20:45:57 +0000 (21:45 +0100)
committerdirkf <fieldhouse@gmx.net>
Tue, 1 Aug 2023 00:05:09 +0000 (01:05 +0100)
youtube_dl/swfinterp.py
youtube_dl/utils.py

index 0c71585753134e93fba8d8de5cee003d31f050c9..e79e0b17f8a1237b83d80e9c7c305d79e8e7be1d 100644 (file)
@@ -727,7 +727,7 @@ class SWFInterpreter(object):
                             stack.append(res)
                             continue
 
-                        assert isinstance(obj, (dict, _ScopeDict)),\
+                        assert isinstance(obj, (dict, _ScopeDict)), \
                             'Accessing member %r on %r' % (pname, obj)
                         res = obj.get(pname, undefined)
                         stack.append(res)
index 36204c8fac09e8aa1a2f7b2ae5d2a8e081f6f11e..1da5a7a38b9ca7bf7a75aee2e8f53b8339acf42c 100644 (file)
@@ -2235,7 +2235,7 @@ def _htmlentity_transform(entity_with_semicolon):
 def unescapeHTML(s):
     if s is None:
         return None
-    assert type(s) == compat_str
+    assert isinstance(s, compat_str)
 
     return re.sub(
         r'&([^&;]+;)', lambda m: _htmlentity_transform(m.group(1)), s)
@@ -3418,7 +3418,7 @@ def _windows_write_string(s, out):
 def write_string(s, out=None, encoding=None):
     if out is None:
         out = sys.stderr
-    assert type(s) == compat_str
+    assert isinstance(s, compat_str)
 
     if sys.platform == 'win32' and encoding is None and hasattr(out, 'fileno'):
         if _windows_write_string(s, out):
@@ -4459,8 +4459,10 @@ TV_PARENTAL_GUIDELINES = {
 
 
 def parse_age_limit(s):
-    if type(s) == int:
-        return s if 0 <= s <= 21 else None
+    if not isinstance(s, bool):
+        age = int_or_none(s)
+        if age is not None:
+            return age if 0 <= age <= 21 else None
     if not isinstance(s, compat_basestring):
         return None
     m = re.match(r'^(?P<age>\d{1,2})\+?$', s)