|
42 | 42 | """ |
43 | 43 |
|
44 | 44 | from collections import OrderedDict as dict_ |
45 | | -from dataclasses import dataclass |
46 | | -from dataclasses import field as dataclass_field |
47 | | -from typing import Any, Callable, ClassVar, Dict, List, Optional, Tuple |
48 | | -from typing import Type as T |
49 | | -from typing import TypeVar, Union, cast |
| 45 | +from dataclasses import dataclass, field as dataclass_field |
| 46 | +from typing import ( |
| 47 | + Any, |
| 48 | + Callable, |
| 49 | + ClassVar, |
| 50 | + Dict, |
| 51 | + List, |
| 52 | + Optional, |
| 53 | + Tuple, |
| 54 | + Type as T, |
| 55 | + TypeVar, |
| 56 | + Union, |
| 57 | + cast, |
| 58 | +) |
50 | 59 |
|
51 | 60 | from bitproto.errors import ( |
52 | 61 | DuplicatedDefinition, |
|
70 | 79 | PROTO_OPTTIONS, |
71 | 80 | OptionDescriptor, |
72 | 81 | OptionDescriptors, |
| 82 | + Validator as OptionValidator, |
73 | 83 | ) |
74 | | -from bitproto.options import Validator as OptionValidator |
75 | 84 | from bitproto.utils import ( |
76 | 85 | cache, |
77 | 86 | conditional_cache, |
@@ -706,21 +715,21 @@ def __repr__(self) -> str: |
706 | 715 | @frozen |
707 | 716 | @dataclass |
708 | 717 | class Int(Integer): |
709 | | - """Int is the signed Integer. |
710 | | - Different from uint, int type only supports capacity: 8, 16, 32, 64. |
711 | | - """ |
| 718 | + """Int is the signed Integer.""" |
712 | 719 |
|
713 | 720 | cap: int = 0 |
714 | 721 |
|
715 | | - @override(Node) |
716 | | - def validate_post_freeze(self) -> None: |
717 | | - if self.cap not in (8, 16, 32, 64): |
718 | | - raise InvalidIntCap.from_token(token=self) |
719 | | - |
720 | 722 | @override(Type) |
721 | 723 | def nbits(self) -> int: |
722 | 724 | return self.cap |
723 | 725 |
|
| 726 | + @override(Node) |
| 727 | + def validate_post_freeze(self) -> None: |
| 728 | + if self._is_missing: |
| 729 | + return |
| 730 | + if not (0 < self.cap <= 64): |
| 731 | + raise InvalidIntCap.from_token(token=self) |
| 732 | + |
724 | 733 | def __repr__(self) -> str: |
725 | 734 | return "<type int{0}>".format(self.cap) |
726 | 735 |
|
|
0 commit comments