@@ -189,15 +189,15 @@ def visit_Num(self, node: ast.Constant) -> None:
189189
190190 def _check_is_magic (self , node : ast .Constant ) -> None :
191191 parent = operators .get_parent_ignoring_unary (node )
192- if isinstance (parent , self ._allowed_parents ):
193- return
194-
195- if node .value in constants .MAGIC_NUMBERS_WHITELIST :
196- return
197192
198- if isinstance (node .value , int ) and node .value <= self ._non_magic_modulo :
193+ if any ((
194+ isinstance (parent , self ._allowed_parents ),
195+ node .value in constants .MAGIC_NUMBERS_WHITELIST ,
196+ isinstance (node .value , int )
197+ and node .value <= self ._non_magic_modulo ,
198+ self ._check_is_number_in_typing_literal (parent ),
199+ )):
199200 return
200-
201201 try :
202202 token = self ._token_dict [node .lineno , node .col_offset ]
203203 except KeyError : # pragma: no cover
@@ -212,6 +212,13 @@ def _check_is_magic(self, node: ast.Constant) -> None:
212212 best_practices .MagicNumberViolation (node , text = real_value ),
213213 )
214214
215+ def _check_is_number_in_typing_literal (self , node : ast .AST | None ) -> bool :
216+ return (
217+ isinstance (node , ast .Subscript )
218+ and isinstance (node .value , ast .Name )
219+ and node .value .id == 'Literal'
220+ )
221+
215222 def _check_is_approximate_constant (self , node : ast .Constant ) -> None :
216223 try :
217224 precision = len (str (node .value ).split ('.' )[1 ])
0 commit comments