File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change 20
20
import mypy .errorcodes as codes
21
21
from mypy import message_registry
22
22
from mypy .checker_shared import TypeCheckerSharedApi
23
+ from mypy .constant_fold import constant_fold_expr
23
24
from mypy .errors import Errors
24
25
from mypy .maptype import map_instance_to_supertype
25
26
from mypy .messages import MessageBuilder
@@ -1005,8 +1006,13 @@ def check_expr(expr: Expression) -> None:
1005
1006
and len (expr .value ) != 1
1006
1007
):
1007
1008
self .msg .requires_int_or_single_byte (context )
1008
- elif isinstance (expr , (StrExpr , BytesExpr )) and len (expr .value ) != 1 :
1009
- self .msg .requires_int_or_char (context )
1009
+ else :
1010
+ if isinstance (folded := constant_fold_expr (expr , "unused" ), str ):
1011
+ value = folded
1012
+ elif isinstance (expr , BytesExpr ):
1013
+ value = expr .value
1014
+ if len (value ) != 1 :
1015
+ self .msg .requires_int_or_char (context )
1010
1016
1011
1017
return check_expr , check_type
1012
1018
You can’t perform that action at this time.
0 commit comments