check virtual lengths, fix imports
This commit is contained in:
parent
4c2adcc5e6
commit
73ba419d64
|
@ -268,7 +268,7 @@ class Elements(ParamsBase, metaclass=ElementsType):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def value_check(cls, value):
|
def value_check(cls, value):
|
||||||
return all(isinstance(v, cls.elem_type) for v in value)
|
return all(isinstance(v, cls.elem_type) for v in value) and len(value) <= cls.length
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def extract_args(cls, *args):
|
def extract_args(cls, *args):
|
||||||
|
@ -316,6 +316,7 @@ class Vector(Elements):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def value_check(cls, value):
|
def value_check(cls, value):
|
||||||
|
# check length limit strictly
|
||||||
return len(value) == cls.length and super().value_check(value)
|
return len(value) == cls.length and super().value_check(value)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -350,7 +351,8 @@ class BytesLike(Elements, metaclass=BytesType):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def value_check(cls, value):
|
def value_check(cls, value):
|
||||||
return isinstance(value, bytes)
|
# check type and virtual length limit
|
||||||
|
return isinstance(value, bytes) and len(value) <= cls.length
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
cls = self.__class__
|
cls = self.__class__
|
||||||
|
@ -376,6 +378,7 @@ class BytesN(BytesLike):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def value_check(cls, value):
|
def value_check(cls, value):
|
||||||
|
# check length limit strictly
|
||||||
return len(value) == cls.length and super().value_check(value)
|
return len(value) == cls.length and super().value_check(value)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
Loading…
Reference in New Issue