Rule request
(I am not sure whether this is a bug or a rule request, sorry if I picked the wrong one.)
Thesis
WPS432 currently is applied to magic numbers within literal types.
foobar: Literal[9001] = 9001
In this example, 9001 inside of Literal is being reported. This behavior should be changed such that this type annotations are ignored.
Reasoning
With how the WPS rules currently work, you are allowed to create a Literal with a str constant, but not with an int or float.
foobar: Literal[9001] = 9001 # not allowed
barfoo: Literal["something"] = "something" # allowed
The only way to have my typed constant is to either use noqa or use int and float as the type, which don't give me the same static guarantees than Literal.
More generally, a magic number in the domain of types is different from a magic number in the domain of values. In the case of Literal the semantic meaning of the number is given by the way it is used to build the whole type. I think this opens up the question how literals should be treated within type annotations.
Rule request
(I am not sure whether this is a bug or a rule request, sorry if I picked the wrong one.)
Thesis
WPS432 currently is applied to magic numbers within literal types.
In this example,
9001inside ofLiteralis being reported. This behavior should be changed such that this type annotations are ignored.Reasoning
With how the WPS rules currently work, you are allowed to create a
Literalwith astrconstant, but not with anintorfloat.The only way to have my typed constant is to either use
noqaor useintandfloatas the type, which don't give me the same static guarantees thanLiteral.More generally, a magic number in the domain of types is different from a magic number in the domain of values. In the case of
Literalthe semantic meaning of the number is given by the way it is used to build the whole type. I think this opens up the question how literals should be treated within type annotations.