Created
April 30, 2020 17:14
-
-
Save mallamanis/c85035ed73d9f26e93cfb83866777055 to your computer and use it in GitHub Desktop.
No string parsing for inf/nan
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @name Use math.inf or math.nan | |
* @description Prefer using math.inf instead of parsing infinity | |
from a string | |
* @kind problem | |
* @tags maintainability | |
* @problem.severity recommendation | |
* @sub-severity low | |
* @precision high | |
* @id py/no-float-inf | |
*/ | |
import python | |
from Call call | |
where call.getFunc().pointsTo(Value::named("float")) | |
and exists(StrConst parsedStr | parsedStr = call.getAPositionalArg() | |
and ( | |
parsedStr.getText().toLowerCase() = "inf" | |
or parsedStr.getText().toLowerCase() = "-inf" | |
or parsedStr.getText().toLowerCase() = "+inf" | |
or parsedStr.getText().toLowerCase() = "infinity" | |
or parsedStr.getText().toLowerCase() = "+infinity" | |
or parsedStr.getText().toLowerCase() = "-infinity" | |
or parsedStr.getText().toLowerCase() = "nan" | |
)) | |
select call, "Use `math.inf` or `math.nan` instead of parsing with `float()`." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment