-
-
Notifications
You must be signed in to change notification settings - Fork 278
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
Add Trystar nodes from python 3.11 #2028
Conversation
What do you need help on with this PR? |
Right now I don't understand why the postinit is never called and handlers never populated, but I did not have enough time to retro-engineer things yet. |
There's anoother tasks for 3.11 though :) |
|
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #2028 +/- ##
==========================================
+ Coverage 92.79% 92.82% +0.03%
==========================================
Files 95 95
Lines 11013 11067 +54
==========================================
+ Hits 10219 10273 +54
Misses 794 794
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Thank you for fixing everything and unblocking the path to 2.17.0 @jacobtylerwalls :D I'm going to add more tests for inference and iterating on parents. |
e96e496
to
b51b29b
Compare
Can't test with the full test suite in pylint because of |
Visit child nodes of TryStar Test children Avoid creating TryExcept under TryStar block range tests Proper coverage of block_range in try star node Add text for name lookup Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com>
47a2544
to
da728ca
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.
I'm late to the party, but I think the typing of the arguments is a bit too permissive. Would be good to narrow those down in a follow up so we don't make this part of the public API before releasing.
def __init__( | ||
self, | ||
*, | ||
lineno: int | None = None, |
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'm a little late to the party, but this feels incorrect. I don't think these should ever be None
right?
:param end_col_offset: The end column this node appears on in the | ||
source code. Note: This is after the last symbol. | ||
""" | ||
self.body: list[NodeNG] = [] |
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 feel like it should be SuccesfulInferenceResult
maybe?
col_offset: int | None = None, | ||
end_lineno: int | None = None, | ||
end_col_offset: int | None = None, | ||
parent: NodeNG | None = None, |
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.
Shouldn't this be LocalsDictNodeNG
?
def postinit( | ||
self, | ||
*, | ||
body: list[NodeNG] | None = None, |
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.
All of these should never be None:
https://github.com/python/typeshed/blob/9472dc10b98570633e8777accf339dcec0179da4/stdlib/_ast.pyi#L178
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.
But why would we bother to make TryStar
the only exception? Wouldn't we just batch them all up with with
, etc.?
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 don't really understand your comment, but I think it's better to be more restrictive where possible since we don't clearly define our public API here. There is just more options to deal with later if we ever want to refactor this.
I do like that these are keyword only!
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.
According to the typing orelse
and finalbody
should also only be Statement
and not NodeNG
I think, but that's another issue 😓
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'm just pointing out that the current typing in this PR matches the typing for many other nodes such as TryExcept
, With
, If
, For
, etc., and doesn't meaningfully contribute to API breakgae if we're going to tighten those all in the future to have one more affected node for the time being. (In fact, it would seem weird to me to consciously fix only one at this time, which would be its own weird API asymmetry-breakage.)
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.
Hm, I think it would have been easier to tighten them now since we're "investigating" the node anyway and make a small comment about the typing being correct somewhere.
The issue is that right now we can't know for sure that any of the typing in astroid
is correct. Marking TryStart
as "reviewed and actually correct" would have been a good first step I think.
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.
@DanielNoord DanielNoord 4 minutes ago
According to the typing orelse and finalbody should also only be Statement and not NodeNG I think, but that's another issue 😓
Interesting. We should decide if we're moving forward with #1867 before delving into that, I would think. And honestly I'd still prefer fixing all affected nodes in one fell swoop. Better release story esp. if we have to tinker with constructors to not allow None, etc., which is more impactful breakage.
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.
Fair enough!
I'm doing that now to double-check things. It's as simple as: diff --git a/pyproject.toml b/pyproject.toml
index 1c8a915ac..f3972f44e 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -88,7 +88,7 @@ test = "pytest"
testpaths = ["tests"]
python_files = ["*test_*.py"]
addopts = "--strict-markers"
-filterwarnings = "error"
+filterwarnings = "ignore::DeprecationWarning"
markers = [
"primer_stdlib: Checks for crashes and errors when running pylint on stdlib",
"primer_external_batch_one: Checks for crashes and errors when running pylint on external libs (batch one)", |
Astroid incorrectly infers the type of the exceptions caught by TryStar ExceptHandler:
In fact:
In |
Thanks, can you open an issue and state the current result in addition to the expected result? |
Type of Changes
Description
Closes #1516
This is a work in progress, I never did that before. I'm creating the class on the model given in the other class although I instinctively really wanted to not use postinit and recursively rebuild nodes inside the class itself instead. Righ tnow it seems postinit do not populate the handlers property. Pushing so we can work collaboratively on it as this is one big piece of #1516