Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Pass challenges with raise #88

Open
F-park opened this issue Jan 18, 2024 · 6 comments
Open

[Bug] Pass challenges with raise #88

F-park opened this issue Jan 18, 2024 · 6 comments

Comments

@F-park
Copy link
Contributor

F-park commented Jan 18, 2024

Bug description

image

If # expect-type-error not in test_code, challenge can pass with raise.

Challenges

  • advanced-forward
  • advanced-never2
@laike9m
Copy link
Owner

laike9m commented Jan 18, 2024

Yes, this is a known issue. I haven't thought of good ways to solve it

@laike9m
Copy link
Owner

laike9m commented Jan 18, 2024

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..

@F-park
Copy link
Contributor Author

F-park commented Jan 18, 2024

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)

@laike9m
Copy link
Owner

laike9m commented Jan 19, 2024

Actually, I find that pyright will ignore whatever code following raise, since it thinks that those code is unreachable.

Example

So it really seems to have no solution..

@F-park
Copy link
Contributor Author

F-park commented Jan 19, 2024

So it really seems to have no solution..

image

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

@laike9m
Copy link
Owner

laike9m commented Jan 19, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants