Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-134733: fix: ast.dump( show_empty=True ) now displays allNone values#134743

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed

Conversation

hunterhogan
Copy link
Contributor

@hunterhoganhunterhogan commentedMay 26, 2025
edited by bedevere-appbot
Loading

Ensure that ast.dump includes all None values when the show_empty flag is set to True.

Also, changedif toelif for consistency.

@sharktide
Copy link
Contributor

Hmmm... It seems as if the ast tests are failing. The tests wantres andexpect to be the same and it isn't getting what it wants

Copy link
Contributor

@sharktidesharktide left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@hunterhogan The issue is that the tests haven't been updated to handle the kind="None" attr.

We could either drop that or update the tests.

@hunterhogan
Copy link
ContributorAuthor

I think I am missing something because the existing tests seem sparse. I made some tests, but I didn't finish integrating them. I don't really know what I am doing. I could use a little help, to be honest.

@hunterhoganhunterhogan marked this pull request as draftMay 27, 2025 05:37
@@ -0,0 +1,1477 @@
import ast

check_node(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

What ischeck_node?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

From the existing tests.

deftest_dump_show_empty(self):
defcheck_node(node,empty,full,**kwargs):
withself.subTest(show_empty=False):
self.assertEqual(
ast.dump(node,show_empty=False,**kwargs),
empty,
)
withself.subTest(show_empty=True):
self.assertEqual(
ast.dump(node,show_empty=True,**kwargs),
full,
)
defcheck_text(code,empty,full,**kwargs):
check_node(ast.parse(code),empty,full,**kwargs)
check_node(
ast.arguments(),
empty="arguments()",
full="arguments(posonlyargs=[], args=[], kwonlyargs=[], kw_defaults=[], defaults=[])",
)
check_node(
# Corner case: there are no real `Name` instances with `id=''`:
ast.Name(id='',ctx=ast.Load()),
empty="Name(id='', ctx=Load())",
full="Name(id='', ctx=Load())",
)

@sharktide
Copy link
Contributor

sharktide commentedMay 27, 2025
edited
Loading

I think I am missing something because the existing tests seem sparse. I made some tests, but I didn't finish integrating them. I don't really know what I am doing. I could use a little help, to be honest.

I'll see what I can do. Busy now will get to this

Copy link
Contributor

@sharktidesharktide left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I'm going file by file.

In the news entry we don't need the entire second sentence.

Copy link
Contributor

@sharktidesharktide left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@hunterhogan You never definedcheck_node.

I'm writing one now. Also, could you please add me as a collaborator to your branch so I can try a few things?

@sharktide
Copy link
Contributor

@hunterhogan
I got a working version of check_node, but I think we should implement this the following way:

test_ast/cases.py
<-- add test cases here in a list -->

test_ast/utils.py
<-- add my version of check_node here -->

test_ast/test_ast.py
<-- Call the cases with my check_node in utils -->

Is it okay if I do this? My version of check_node needs a specific format which would require rewriting all your tests

@hunterhogan
Copy link
ContributorAuthor

I was attempting to integrate with the existing tests.

deftest_dump_show_empty(self):
defcheck_node(node,empty,full,**kwargs):
withself.subTest(show_empty=False):
self.assertEqual(
ast.dump(node,show_empty=False,**kwargs),
empty,
)
withself.subTest(show_empty=True):
self.assertEqual(
ast.dump(node,show_empty=True,**kwargs),
full,
)
defcheck_text(code,empty,full,**kwargs):
check_node(ast.parse(code),empty,full,**kwargs)
check_node(
ast.arguments(),
empty="arguments()",
full="arguments(posonlyargs=[], args=[], kwonlyargs=[], kw_defaults=[], defaults=[])",
)
check_node(
# Corner case: there are no real `Name` instances with `id=''`:
ast.Name(id='',ctx=ast.Load()),
empty="Name(id='', ctx=Load())",
full="Name(id='', ctx=Load())",
)

I'm in over my head.

@hunterhogan
Copy link
ContributorAuthor

I am not currently capable of accomplishing this task.

#134718 will probably resolve it, though.

@sharktide
Copy link
Contributor

@hunterhogan We'll see. Thanks for opening this PR and giving it a shot though!

hunterhogan reacted with heart emoji

@sharktide
Copy link
Contributor

I'm going to try to revive this

@serhiy-storchaka
Copy link
Member

Please, ensure that tests are passed before creating a PR. I suspect also that the change proposed in this PR has flaws. Tests could expose them.

@sharktide
Copy link
Contributor

I'll do my best

@sharktide
Copy link
Contributor

I'm going to cherry-pick your code into a branch on my fork

sharktide added a commit to sharktide/cpython that referenced this pull requestMay 28, 2025
@hunterhogan
Copy link
ContributorAuthor

Please, ensure that tests are passed before creating a PR. I suspect also that the change proposed in this PR has flaws. Tests could expose them.

@serhiy-storchaka The existing tests didn't expose the obvious flaw in ast.dump. And the existing tests are erroneously failing when the function is doing what it is supposed to do.

Are you willing to put some skin in the game? ast.dump may have flaws, but my changes didn't introduce them. US$500? That's ~20% of all of my money.

ZeroIntensity, zware, sharktide, Eclips4, lubaskinc0de, and TurtleOld reacted with thumbs down emoji

@sharktide
Copy link
Contributor

@hunterhogan Please do not bet on github.

@hunterhogan
Copy link
ContributorAuthor

Changes made

image

Baseless response

image

Calling out bad behavior

image

Community

image
image

I'm out

@brettcannon
Copy link
Member

Also please keep things civil.

@hunterhogan
Copy link
ContributorAuthor

Also please keep things civil.

Thank you for quickly responding with false equivalence. It will help me have accurate expectations if I try to contribute again.

@sharktide
Copy link
Contributor

@hunterhogan No offense, but seems like a bit of an overreaction. I am taking the time to write this because no one is denying that you are a bad programmer, but it is a bit 'uncivil' to get mad at people and bet money over PRs and Issues.

Nothing personal, but please, there was nothing wrong with@serhiy-storchaka's comment IMO, so don't overreact if it just questioned this issue/PR. It is just called triaging and there was nothing against you.

@brettcannon
Copy link
Member

Based on the consistent tone in this PR I'm going to lock it down.

@pythonpython locked astoo heatedand limited conversation to collaboratorsMay 31, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@serhiy-storchakaserhiy-storchakaserhiy-storchaka left review comments

@sharktidesharktidesharktide requested changes

@isidenticalisidenticalAwaiting requested review from isidenticalisidentical is a code owner

@JelleZijlstraJelleZijlstraAwaiting requested review from JelleZijlstraJelleZijlstra is a code owner

@Eclips4Eclips4Awaiting requested review from Eclips4Eclips4 is a code owner

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@hunterhogan@sharktide@serhiy-storchaka@brettcannon

[8]ページ先頭

©2009-2025 Movatter.jp