fix bytes value check, fix default-type checking
This commit is contained in:
parent
b6cf809d9b
commit
cd5f59eb74
|
@ -171,7 +171,10 @@ class ParamsMeta(DefaultingTypeMeta):
|
|||
if hasattr(self.__class__, name):
|
||||
res[name] = getattr(self.__class__, name)
|
||||
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(
|
||||
"cannot create parametrized class with param {} as {} of type {}".format(param, name, typ))
|
||||
res[name] = param
|
||||
|
@ -246,8 +249,10 @@ class List(AbstractList):
|
|||
|
||||
|
||||
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
|
||||
def default(cls):
|
||||
|
@ -274,7 +279,7 @@ class BytesLike(AbstractList, metaclass=BytesMeta):
|
|||
|
||||
@classmethod
|
||||
def value_check(cls, value):
|
||||
return len(value) == cls.length and isinstance(value, bytes)
|
||||
return isinstance(value, bytes)
|
||||
|
||||
def __str__(self):
|
||||
cls = self.__class__
|
||||
|
@ -283,9 +288,6 @@ class BytesLike(AbstractList, metaclass=BytesMeta):
|
|||
|
||||
class Bytes(BytesLike):
|
||||
|
||||
def value_check(self, value):
|
||||
return len(value) <= self.__class__.length and isinstance(value, bytes)
|
||||
|
||||
@classmethod
|
||||
def default(cls):
|
||||
return b''
|
||||
|
@ -297,3 +299,7 @@ class BytesN(BytesLike):
|
|||
def default(cls):
|
||||
return b'\x00' * cls.length
|
||||
|
||||
@classmethod
|
||||
def value_check(cls, value):
|
||||
return len(value) == cls.length and super().value_check(value)
|
||||
|
||||
|
|
Loading…
Reference in New Issue