Skip to content

Comments

gh-137600: Promote ast node constructor deprecation warnings to errors#137601

Open
brianschubert wants to merge 22 commits intopython:mainfrom
brianschubert:gh-137600-ast-constr-errors
Open

gh-137600: Promote ast node constructor deprecation warnings to errors#137601
brianschubert wants to merge 22 commits intopython:mainfrom
brianschubert:gh-137600-ast-constr-errors

Conversation

@brianschubert
Copy link
Contributor

@brianschubert brianschubert commented Aug 9, 2025

@brianschubert
Copy link
Contributor Author

@picnixz As mentioned in #121162 (comment), now that the constructors raise on missing and unknown fields, some of the checks that were added for copy.replace support are no longer needed, so I went ahead and removed them (de5564a). Based on the tests, it looks like things are working correctly, but I'd appreciate if you could take a look to make sure I didn't break anything :-)

@brianschubert brianschubert linked an issue Aug 9, 2025 that may be closed by this pull request
@picnixz
Copy link
Member

picnixz commented Aug 10, 2025

This takes me back as the original PR is one of my very first contributions to CPython!

@picnixz picnixz self-requested a review August 10, 2025 06:55
Copy link
Member

@picnixz picnixz left a comment

Choose a reason for hiding this comment

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

I'd suggest using msg = ... + re.escape() for assertRaisesRegex() where 80 chars limit is exceeded.

brianschubert and others added 2 commits August 18, 2025 17:20
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
@JelleZijlstra
Copy link
Member

@picnixz do you have any further feedback?

Copy link
Member

@picnixz picnixz left a comment

Choose a reason for hiding this comment

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

I do not but I actually had a pending review that I started 1 month ago. They are mainly for improving coverage and wording but they are optional.

brianschubert and others added 3 commits October 26, 2025 20:18
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
brianschubert and others added 2 commits October 27, 2025 08:00
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
@brianschubert
Copy link
Contributor Author

@JelleZijlstra friendly ping! Anything else needed here?

Copy link
Member

@JelleZijlstra JelleZijlstra left a comment

Choose a reason for hiding this comment

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

Thanks, left some suggestions for the tests.

# Custom attribute assignment is allowed
x.foo = 5
self.assertEqual(x.foo, 5)
del x.foo
Copy link
Member

Choose a reason for hiding this comment

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

Why is this needed? Doesn't the object get deleted anyway?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fair point, I guess at the time I was trying to test that deletion is well behaved too? I don't see much precedence for testing that elsewhere in the tests, so I think I'll remove it


with self.assertRaises(AttributeError):
x.value
msg = "ast.Constant.__init__ missing 1 required positional argument: 'value'"
Copy link
Member

Choose a reason for hiding this comment

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

This test now feels out of scope for the test function. If we're already sufficiently testing that this case errors out (I assume we are), let's just remove this line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, this doesn't have anything to do the node attributes anymore (I should have read the test name!). I'll remove it.

# Arbitrary keyword arguments are supported (but deprecated)
with self.assertWarns(DeprecationWarning):
self.assertEqual(ast.Constant(1, foo='bar').foo, 'bar')
# Arbitrary keyword arguments are not supported
Copy link
Member

Choose a reason for hiding this comment

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

Same here, this is now testing something unrelated to what this function is about.

Copy link
Member

Choose a reason for hiding this comment

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

My intent here was to be sure we were ignoring kwargs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed as well, I'll remove it.

Not accepting arbitrary kwargs has coverage elsewhere, e.g. here:
https://github.com/brianschubert/cpython/blob/f3e21e6a37d5e479d4d6f597544b2036f6a6ae3d/Lib/test/test_ast/test_ast.py#L588

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Promote ast node constructor deprecation warnings to errors

4 participants