-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[possibly-used-before-assignment] Avoid FP for typing.NoReturn #9714
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
in ( | ||
*TYPING_NORETURN, | ||
# In Python 3.7 - 3.8, NoReturn is alias of '_SpecialForm' | ||
"typing._SpecialForm", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll be dropping support for 3.8 in the next minor release, so this inelegance doesn't bother me ATM.
Codecov ReportAll modified and coverable lines are covered by tests β
Additional details and impacted files@@ Coverage Diff @@
## main #9714 +/- ##
==========================================
- Coverage 95.85% 95.84% -0.01%
==========================================
Files 174 174
Lines 18873 18878 +5
==========================================
+ Hits 18090 18094 +4
- Misses 783 784 +1
|
This comment has been minimized.
This comment has been minimized.
I'm on the fence about this one. On the one hand, it's going to prevent false positives. And we have false positives for code that is too dynamic for astroid to understand. But on the other hand, one of the value proposition of pylint is not trusting the typing. If we start trusting the typing then we're going to raise the same class of error that type checker already raise, and they do that better than us and faster than us. Also, if we don't do it generically we're going to have some message that trust the typing and some that don't and how are we drawing the line when someone ask for typing use making the point that "possibly-user-before-assignment" does it for "NoReturn" already ? Then again I don't see massive improvements happening in astroid's inference any time soon. |
I hear that. I think NoReturn is very special -- it's basically assert_never, which is basically a more expressive pylint disable. Allowing someone to use a stdlib feature that works well with type checkers instead of a pylint disable is a pretty isolated case compared to always trusting typing. |
I like the idea if seeing some type hint as implicit disables. A passing thought : Taking other tool's noqas into account is somewhat similar and would also make pylint more useful. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the fact that the genericity if the code permits to also makes 'unreachable' better. It's done properly because it's easy to see that kind of helper reuse as a dirty source of unintented side effects.
@DanielNoord do you want to chime in :) ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it! However, I would like to document that this is a special case and not something we do for other checks. Then we have something we can point to when more requests start coming in.
Other checks or other type annotation concepts? I've made change in the general util, I think we probably should simplify the code for other checks by using the common utils more, so I don't know there's much more to document. |
Type annotation concepts. I meant in the |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. (The last commit's CI need to run so I guess we should remove [ci skip])
Sounds good, I forgot that this repo doesn't really allow that. I'll squash and push. |
256f282
to
c68b813
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wonderful I can just squash with the original author intended commit message β’οΈ
Do you agree with a release just after the backport ?
The backport to
To backport manually, run these commands in your terminal: # Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-maintenance/3.2.x maintenance/3.2.x
# Navigate to the new working tree
cd .worktrees/backport-maintenance/3.2.x
# Create a new branch
git switch --create backport-9714-to-maintenance/3.2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 a5a77f6e891f6e143439d19b5e7f0a29eb5ea1cd
# Push it to GitHub
git push --set-upstream origin backport-9714-to-maintenance/3.2.x
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-maintenance/3.2.x Then, create a pull request where the |
#9714) (#9742) Co-authored-by: Jacob Walls <[email protected]>
Type of Changes
Description
Closes #9674 for the general case, but not necessarily for pytest.skip due to the following: