fix bytes value check, fix default-type checking

This commit is contained in:
protolambda 2019-06-20 19:55:53 +02:00
parent b6cf809d9b
commit cd5f59eb74
No known key found for this signature in database
GPG Key ID: EC89FDBB2B4C7623
1 changed files with 13 additions and 7 deletions

View File

@ -171,7 +171,10 @@ class ParamsMeta(DefaultingTypeMeta):
if hasattr(self.__class__, name): if hasattr(self.__class__, name):
res[name] = getattr(self.__class__, name) res[name] = getattr(self.__class__, name)
else: else:
if not isinstance(param, typ): if typ == TypeWithDefault:
if not (isinstance(param, bool) or isinstance(param, DefaultingTypeMeta)):
raise TypeError("expected param {} as {} to have a type default".format(param, name, typ))
elif not isinstance(param, typ):
raise TypeError( raise TypeError(
"cannot create parametrized class with param {} as {} of type {}".format(param, name, typ)) "cannot create parametrized class with param {} as {} of type {}".format(param, name, typ))
res[name] = param res[name] = param
@ -246,8 +249,10 @@ class List(AbstractList):
class Vector(AbstractList, metaclass=AbstractListMeta): class Vector(AbstractList, metaclass=AbstractListMeta):
def value_check(self, value):
return len(value) == self.__class__.length and super().value_check(value) @classmethod
def value_check(cls, value):
return len(value) == cls.length and super().value_check(value)
@classmethod @classmethod
def default(cls): def default(cls):
@ -274,7 +279,7 @@ class BytesLike(AbstractList, metaclass=BytesMeta):
@classmethod @classmethod
def value_check(cls, value): def value_check(cls, value):
return len(value) == cls.length and isinstance(value, bytes) return isinstance(value, bytes)
def __str__(self): def __str__(self):
cls = self.__class__ cls = self.__class__
@ -283,9 +288,6 @@ class BytesLike(AbstractList, metaclass=BytesMeta):
class Bytes(BytesLike): class Bytes(BytesLike):
def value_check(self, value):
return len(value) <= self.__class__.length and isinstance(value, bytes)
@classmethod @classmethod
def default(cls): def default(cls):
return b'' return b''
@ -297,3 +299,7 @@ class BytesN(BytesLike):
def default(cls): def default(cls):
return b'\x00' * cls.length return b'\x00' * cls.length
@classmethod
def value_check(cls, value):
return len(value) == cls.length and super().value_check(value)