-
-
Notifications
You must be signed in to change notification settings - Fork 277
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
Change frame
and scope
of NamedExpr
for certain parents
#1221
Conversation
Keep forgetting that assignment expressions are >3.8... Oops. Will fix! |
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 tested the change against HomeAssistant and didn't notice any regression. Seems ok.
Could you add one more test case for NamedExpr
in Comprehensions
?
[y for i in (1, 2) if (y := i ** 2)]
I'll the extra test tonight. Btw, do we consider this breaking? Do we expect users to be dependent on the fact that this wrong previously? |
👍🏻
Do you mean at what point does a bug become a feature? ;) |
😃 I'll add a changelog entry then as well! |
We didn't actually catch the |
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 did test again. Seems to work still. Left some minor last comments. Let me know what you think.
Co-authored-by: Marc Mueller <[email protected]>
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! Thanks, @DanielNoord 🐬
Co-authored-by: Marc Mueller <[email protected]>
Thanks for the help @cdce8p! Btw, if you ever get the time to do it I would appreciate it if you could take a look at the typing of The problem is as follows.
Adding So we have BaseClass, Inheritor and SubInheritor where the return type of BaseClass and SubInheritor should be similar but Inheritor and some of its other inheritors (Module, FunctionDef and ClassDef) have a different annotation. Is this something that can be easily/cleanly fixed with annotation? I could also open an issue to track this. I think it would be helpful in |
Co-authored-by: Marc Mueller <[email protected]>
@@ -4225,6 +4225,46 @@ def postinit(self, target: NodeNG, value: NodeNG) -> None: | |||
self.target = target | |||
self.value = value | |||
|
|||
def frame(self): |
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 suppose it was discussed with Marc (sorry I did not read all the comment), and adding typing here should be done later and the docstring is enough for now ?
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 think the docstring is enough for now. I will need some guidance from @cdce8p to actually fully type frame()
.
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.
Yeah, typing frame
is a bit complicated due to the current class / mixin structure. We should tackle that separately.
of parent nodes. | ||
""" | ||
module = builder.parse( | ||
""" |
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.
Maybe we can create a fixture for the example? It seems the same example is used for frame and scope.
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 could, although that might also make these tests less flexible in the future. I can explore this, but personally I'm fine with keeping it like this.
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.
The example is the same. I'm just not sure it does make much sense to create a fixture for it.
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.
Let's keep it that way.
@DanielNoord This is indeed a bit complicated. At the moment I can only think of two options
I guess |
Is was thinking of removing Is that something you would consider? |
By removing it from Just an idea:
|
Maybe we can create an issue with the current frame typing discussion so it's not lost after the merge ? |
Which has a So, I would assume
I like this idea as well. I am happy to create a PR that implements this, but is that necessary with the knowledge that |
Good point. Don't know about typing though. If you like, try to see if you can make it work. Open a WIP PR and I can take a look. |
Steps
Description
/CC @cdce8p
This changes the
frame
andscope
methods ofNamedExpr
whenever they occur inFunctionDef
orClassDef
.I have tested against current
main
ofpylint
and did not experience any regressions.Type of Changes
Related Issue