File tree 1 file changed +28
-0
lines changed
1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,34 @@ macro_rules! type_check {
35
35
} ;
36
36
}
37
37
38
+ #[ macro_export]
39
+ macro_rules! check_but_allow_none {
40
+ ( $vm: ident, $arg: ident, $expected_type: expr ) => {
41
+ let $arg = match $arg {
42
+ Some ( arg) => {
43
+ if arg. is( & $vm. get_none( ) ) {
44
+ None
45
+ } else {
46
+ if $crate:: obj:: objtype:: real_isinstance( $vm, arg, & $expected_type) ? {
47
+ Some ( arg)
48
+ } else {
49
+ let arg_typ = arg. typ( ) ;
50
+ let actual_type = $vm. to_pystr( & arg_typ) ?;
51
+ let expected_type_name = $vm. to_pystr( & $expected_type) ?;
52
+ return Err ( $vm. new_type_error( format!(
53
+ "{} must be a {}, not {}" ,
54
+ stringify!( $arg) ,
55
+ expected_type_name,
56
+ actual_type
57
+ ) ) ) ;
58
+ }
59
+ }
60
+ }
61
+ None => None ,
62
+ } ;
63
+ } ;
64
+ }
65
+
38
66
#[ macro_export]
39
67
macro_rules! arg_check {
40
68
( $vm: ident, $args: ident ) => {
You can’t perform that action at this time.
0 commit comments