Skip to content

Commit

Permalink
[utils] Avoid comparing type(var), etc, to pass new Linter rules
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkf committed Aug 1, 2023
1 parent abef534 commit 7d965e6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion youtube_dl/swfinterp.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ def resfunc(args):
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)
Expand Down
10 changes: 6 additions & 4 deletions youtube_dl/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -3418,7 +3418,7 @@ def next_nonbmp_pos(s):
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):
Expand Down Expand Up @@ -4459,8 +4459,10 @@ def encode_compat_str(string, encoding=preferredencoding(), errors='strict'):


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)
Expand Down

0 comments on commit 7d965e6

Please sign in to comment.