File tree 1 file changed +23
-0
lines changed
crates/red_knot_python_semantic/src/types
1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -2211,6 +2211,7 @@ impl<'db> TypeInferenceBuilder<'db> {
2211
2211
2212
2212
match ( op, self . infer_expression ( operand) ) {
2213
2213
( UnaryOp :: USub , Type :: IntLiteral ( value) ) => Type :: IntLiteral ( -value) ,
2214
+ ( UnaryOp :: Not , Type :: BooleanLiteral ( value) ) => Type :: BooleanLiteral ( !value) ,
2214
2215
_ => Type :: Unknown , // TODO other unary op types
2215
2216
}
2216
2217
}
@@ -3142,6 +3143,28 @@ mod tests {
3142
3143
Ok ( ( ) )
3143
3144
}
3144
3145
3146
+ #[ test]
3147
+ fn not_boolean_literal ( ) -> anyhow:: Result < ( ) > {
3148
+ let mut db = setup_db ( ) ;
3149
+
3150
+ db. write_file (
3151
+ "src/a.py" ,
3152
+ r#"
3153
+ w = True
3154
+ x = False
3155
+ y = not w
3156
+ z = not x
3157
+
3158
+ "# ,
3159
+ ) ?;
3160
+ assert_public_ty ( & db, "src/a.py" , "w" , "Literal[True]" ) ;
3161
+ assert_public_ty ( & db, "src/a.py" , "x" , "Literal[False]" ) ;
3162
+ assert_public_ty ( & db, "src/a.py" , "y" , "Literal[False]" ) ;
3163
+ assert_public_ty ( & db, "src/a.py" , "z" , "Literal[True]" ) ;
3164
+
3165
+ Ok ( ( ) )
3166
+ }
3167
+
3145
3168
#[ test]
3146
3169
fn string_type ( ) -> anyhow:: Result < ( ) > {
3147
3170
let mut db = setup_db ( ) ;
You can’t perform that action at this time.
0 commit comments