You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## Summary
Following up from earlier discussion on Discord, this PR adds logic to
flag casts as redundant when the inferred type of the expression is the
same as the target type. It should follow the semantics from
[mypy](python/mypy#1705).
Example:
```python
def f() -> int:
return 10
# error: [redundant-cast] "Value is already of type `int`"
cast(int, f())
```
Copy file name to clipboardExpand all lines: knot.schema.json
+10
Original file line number
Diff line number
Diff line change
@@ -610,6 +610,16 @@
610
610
}
611
611
]
612
612
},
613
+
"redundant-cast": {
614
+
"title": "detects redundant `cast` calls",
615
+
"description": "## What it does\nDetects redundant `cast` calls where the value already has the target type.\n\n## Why is this bad?\nThese casts have no effect and can be removed.\n\n## Example\n```python\ndef f() -> int:\n return 10\n\ncast(int, f()) # Redundant\n```",
616
+
"default": "warn",
617
+
"oneOf": [
618
+
{
619
+
"$ref": "#/definitions/Level"
620
+
}
621
+
]
622
+
},
613
623
"static-assert-error": {
614
624
"title": "Failed static assertion",
615
625
"description": "## What it does\nMakes sure that the argument of `static_assert` is statically known to be true.\n\n## Examples\n```python\nfrom knot_extensions import static_assert\n\nstatic_assert(1 + 1 == 3) # error: evaluates to `False`\n\nstatic_assert(int(2.0 * 3.0) == 6) # error: does not have a statically known truthiness\n```",
0 commit comments