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

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
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.

3 participants
@hunterhogan@sharktide@serhiy-storchaka

[8]ページ先頭

©2009-2025 Movatter.jp