File tree Expand file tree Collapse file tree 5 files changed +12
-8
lines changed Expand file tree Collapse file tree 5 files changed +12
-8
lines changed Original file line number Diff line number Diff line change @@ -46,18 +46,18 @@ pub struct CodeObject {
46
46
pub source_path : String ,
47
47
pub first_line_number : usize ,
48
48
pub obj_name : String , // Name of the object that created this code object
49
- pub incognito : bool ,
50
49
}
51
50
52
51
bitflags ! {
53
52
#[ derive( Serialize , Deserialize ) ]
54
- pub struct CodeFlags : u8 {
53
+ pub struct CodeFlags : u16 {
55
54
const HAS_DEFAULTS = 0x01 ;
56
55
const HAS_KW_ONLY_DEFAULTS = 0x02 ;
57
56
const HAS_ANNOTATIONS = 0x04 ;
58
57
const NEW_LOCALS = 0x08 ;
59
58
const IS_GENERATOR = 0x10 ;
60
59
const IS_COROUTINE = 0x20 ;
60
+ const INCOGNITO = 1 << 15 ;
61
61
}
62
62
}
63
63
@@ -394,7 +394,6 @@ impl CodeObject {
394
394
source_path,
395
395
first_line_number,
396
396
obj_name,
397
- incognito : false ,
398
397
}
399
398
}
400
399
@@ -451,6 +450,10 @@ impl CodeObject {
451
450
}
452
451
Display ( self )
453
452
}
453
+
454
+ pub fn incognito ( & self ) -> bool {
455
+ self . flags . contains ( CodeFlags :: INCOGNITO )
456
+ }
454
457
}
455
458
456
459
impl fmt:: Display for CodeObject {
Original file line number Diff line number Diff line change @@ -189,7 +189,8 @@ impl<O: OutputStream> Compiler<O> {
189
189
}
190
190
191
191
fn push_output ( & mut self , mut code : CodeObject ) {
192
- code. incognito = self . opts . incognito ;
192
+ code. flags
193
+ . set ( bytecode:: CodeFlags :: INCOGNITO , self . opts . incognito ) ;
193
194
self . output_stack . push ( code. into ( ) ) ;
194
195
}
195
196
Original file line number Diff line number Diff line change @@ -103,7 +103,7 @@ impl PyCodeRef {
103
103
}
104
104
105
105
#[ pyproperty]
106
- fn co_flags ( self ) -> u8 {
106
+ fn co_flags ( self ) -> u16 {
107
107
self . code . flags . bits ( )
108
108
}
109
109
}
Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ impl FrameRef {
31
31
32
32
#[ pyproperty]
33
33
fn f_globals ( self , vm : & VirtualMachine ) -> PyResult < PyDictRef > {
34
- if self . code . incognito {
34
+ if self . code . incognito ( ) {
35
35
Err ( vm. new_type_error ( "Can't get f_globals on an incognito frame" . to_owned ( ) ) )
36
36
} else {
37
37
Ok ( self . scope . globals . clone ( ) )
@@ -40,7 +40,7 @@ impl FrameRef {
40
40
41
41
#[ pyproperty]
42
42
fn f_locals ( self , vm : & VirtualMachine ) -> PyResult < PyDictRef > {
43
- if self . code . incognito {
43
+ if self . code . incognito ( ) {
44
44
Err ( vm. new_type_error ( "Can't get f_locals on an incognito frame" . to_owned ( ) ) )
45
45
} else {
46
46
Ok ( self . scope . get_locals ( ) )
Original file line number Diff line number Diff line change @@ -281,7 +281,7 @@ impl PyFunction {
281
281
282
282
#[ pyproperty( magic) ]
283
283
fn globals ( & self , vm : & VirtualMachine ) -> PyResult < PyDictRef > {
284
- if self . code . incognito {
284
+ if self . code . incognito ( ) {
285
285
Err ( vm. new_type_error ( "Can't get __globals__ on an incognito function" . to_owned ( ) ) )
286
286
} else {
287
287
Ok ( self . scope . globals . clone ( ) )
You can’t perform that action at this time.
0 commit comments