Skip to content

Commit

Permalink
internal/utils: replaced all references to types.TypeType which is …
Browse files Browse the repository at this point in the history
…missing in Python3 with `builtins.type`.
  • Loading branch information
arizvisa committed Dec 3, 2020
1 parent 845b49a commit cba2d10
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions base/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ def result(wrapped):

# validate type arguments
for n, t in t_args.iteritems():
if not isinstance(t, (types.TypeType, types.TupleType)) and t not in {callable}:
error_keywords = ("{:s}={!s}".format(n, t.__name__ if isinstance(t, types.TypeType) or t in {callable} else '|'.join(t_.__name__ for t_ in t) if hasattr(t, '__iter__') else "{!r}".format(t)) for n, t in t_args.iteritems())
if not isinstance(t, (builtins.type, builtins.tuple)) and t not in {callable}:
error_keywords = ("{:s}={!s}".format(n, t.__name__ if isinstance(t, builtins.type) or t in {callable} else '|'.join(t_.__name__ for t_ in t) if hasattr(t, '__iter__') else "{!r}".format(t)) for n, t in t_args.iteritems())
raise internal.exceptions.InvalidParameterError(u"@{:s}({:s}) : The value ({!s}) specified for parameter \"{:s}\" is not a supported type.".format('.'.join([__name__, cls.__name__]), ', '.join(error_keywords), t, string.escape(n, '"')))
continue

Expand All @@ -214,12 +214,12 @@ def result(wrapped):
for c in other:
cls.ex_function(c)
except:
error_keywords = ("{:s}={!s}".format(n, t.__name__ if isinstance(t, types.TypeType) or t in {callable} else '|'.join(t_.__name__ for t_ in t) if hasattr(t, '__iter__') else "{!r}".format(t)) for n, t in t_args.iteritems())
error_keywords = ("{:s}={!s}".format(n, t.__name__ if isinstance(t, builtins.type) or t in {callable} else '|'.join(t_.__name__ for t_ in t) if hasattr(t, '__iter__') else "{!r}".format(t)) for n, t in t_args.iteritems())
raise internal.exceptions.InvalidParameterError(u"@{:s}({:s}) : The specified callable{:s} {!r} {:s} not of a valid type.".format('.'.join([__name__, cls.__name__]), ', '.join(error_keywords), '' if len(other) == 1 else 's', other, 'is' if len(other) == 1 else 'are'))

# throw an exception if we were given an unexpected number of arguments
if len(other) > 1:
error_keywords = ("{:s}={!s}".format(n, t.__name__ if isinstance(t, types.TypeType) or t in {callable} else '|'.join(t_.__name__ for t_ in t) if hasattr(t, '__iter__') else "{!r}".format(t)) for n, t in t_args.iteritems())
error_keywords = ("{:s}={!s}".format(n, t.__name__ if isinstance(t, builtins.type) or t in {callable} else '|'.join(t_.__name__ for t_ in t) if hasattr(t, '__iter__') else "{!r}".format(t)) for n, t in t_args.iteritems())
raise internal.exceptions.InvalidParameterError(u"@{:s}({:s}) : More than one callable ({:s}) was specified to add a case to. Refusing to add cases to more than one callable.".format('.'.join([__name__, cls.__name__]), ', '.join(error_keywords), ', '.join("\"{:s}\"".format(string.escape(c.co_name if isinstance(c, types.CodeType) else c.__name__, '"')) for c in other)))
return result

Expand Down Expand Up @@ -260,7 +260,7 @@ def Fargsiter(names=args, values=parameters):
continue

param_type = parameters[item]
if isinstance(param_type, types.TypeType) or param_type in {callable}:
if isinstance(param_type, builtins.type) or param_type in {callable}:
yield item, param_type.__name__
elif hasattr(param_type, '__iter__'):
yield item, '|'.join(t.__name__ for t in flatten(param_type))
Expand Down Expand Up @@ -379,7 +379,7 @@ def reconstructor(cls, n):
return lambda f: type(n)(f)
if isinstance(n, types.InstanceType):
return lambda f: types.InstanceType(type(n), dict(f.__dict__))
if isinstance(n, (types.TypeType, types.ClassType)):
if isinstance(n, (builtins.type, types.ClassType)):
return lambda f: type(n)(n.__name__, n.__bases__, dict(f.__dict__))
raise internal.exceptions.InvalidTypeOrValueError(type(n))

Expand Down Expand Up @@ -1006,7 +1006,7 @@ def constructor(cls, callable):
return lambda method, mt=callable.__class__: types.InstanceType(mt, dict(method.__dict__))

# otherwise if it's a class or a type, then we just need to create the object with its bases
elif isinstance(n, (types.TypeType, types.ClassType)):
elif isinstance(n, (builtins.type, types.ClassType)):
return lambda method, t=callable.__class__, name=callable.__name__, bases=callable.__bases__: t(name, bases, dict(method.__dict__))

# if we get here, then we have no idea what kind of type `callable` is
Expand Down

0 comments on commit cba2d10

Please sign in to comment.