-
-
Notifications
You must be signed in to change notification settings - Fork 307
Support isinstance constraints in inference
#2846
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
Conversation
Codecov Reportβ
All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2846 +/- ##
==========================================
+ Coverage 93.35% 93.39% +0.04%
==========================================
Files 92 92
Lines 11190 11208 +18
==========================================
+ Hits 10446 10468 +22
+ Misses 744 740 -4
Flags with carried forward coverage won't be shown. Click here to find out more.
π New features to boost your workflow:
|
|
Seems like test coverage is lacking. Shouldn't be an issue to get it up to 100%, but I would like a review first to see if this implementation makes sense. |
jacobtylerwalls
left a comment
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!
As we do more of these, it would be nice to add a CI step that installs pylint and runs the primer. I had an experiment (work in progress) at jacobtylerwalls#157 and
pylint-dev/pylint@main...jacobtylerwalls:pylint:run-with-custom-astroid. Something for later.
DanielNoord
left a comment
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.
@jacobtylerwalls Should this be merged for 4.0.0 considering we already released a RC? Feels like a big change to include after a RC.
|
I wondered as well, happy to wait for 4.1. Let's release 4.0 final tomorrow in that case. |
Let's do so, especially as we haven't tested this with |
Pierre-Sassoulas
left a comment
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.
This is neat ! Glad to see that the constraint api is getting some love.
b3b9dd4
e5217a2 to
b3b9dd4
Compare
b3b9dd4 to
010503c
Compare
010503c to
16032d5
Compare
|
Hey @zenlyj π I think this is mergeable. What do we need for the pylint job to pass, do we need a separate PR to unblock, or is it just a rebase? |
|
This pylint issue I fixed on main then forgot I fixed it and fixed it again on maintenance 2 week later... so I can tell you this is just a rebase π (Need 325ebf6) |
|
In that case, I'll just pull it in π |
Type of Changes
Description
These changes implements the constraint interface to add a new constraint -
TypeConstraintto improve the accuracy of inference for objects used in type-narrowing guards.Currently, the implementation only supports the
isinstancepattern, but it should be relatively straightforward to extend it to support the negated case (not isinstance) in the future.To determine whether an object is an instance of the given types, the implementation reuses existing inference mechanism for
isinstanceinbrains.Refs pylint-dev/pylint#1162
Refs pylint-dev/pylint#4635
Refs pylint-dev/pylint#10469