Python-Type-Challenges
Python-Type-Challenges copied to clipboard
[Bug] Pass challenges with `raise`
Bug description
If # expect-type-error not in test_code, challenge can pass with raise.
Challenges
- advanced-forward
- advanced-never2
Yes, this is a known issue. I haven't thought of good ways to solve it
Took another look. "advanced-forward" should be easy to fix, but never2 is hard, as I haven't found a way to force pyright to fail..
If we can insert some imports before user_code and add "reportUnusedImport": true to pyrightconfig.json, it is easy to solve.
advanced-forward need to force user to annotate return_type for function
# advanced-forward-fix
## End of your code ##
+# pyright: analyzeUnannotatedFunctions=false
from typing import assert_type
inst = MyClass(x=1)
assert_type(inst.copy(), MyClass)
Actually, I find that pyright will ignore whatever code following raise, since it thinks that those code is unreachable.
So it really seems to have no solution..
So it really seems to have no solution..
mypy can detect the name-defined error although code is unreachable, I think we can mix mypy with pyright.
If we add the below to pyproject.toml, mypy will show test.py:4: error: Statement is unreachable [unreachable]
[tool.mypy]
warn_unreachable = true
Using sourcery is a no-go, using mypy maybe could be an option but certainly would complicate things. Another option is to create a special rule just for raise and warn users about it. I'll leave this one open and think about it.