GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-104799: Default missing lists in AST to the empty list by JelleZijlstra · Pull Request #104834 · python/cpython

Conversation

@JelleZijlstra

@JelleZijlstra JelleZijlstra commented May 24, 2023 •
edited by github-actions Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Motivated by #104799: avoid breaking backward compatibility with the manual creation of ast.FunctionDef nodes. Now, if a list-type field is missing, we simply default to the empty list.

This affects all AST nodes though, not just the new ones.

  • Issue: PEP-695: Potentially breaking changes made to __match_args__ attributes of AST nodes #104799

📚 Documentation preview 📚: https://cpython-previews--104834.org.readthedocs.build/

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
JelleZijlstra added 3 commits May 23, 2023 18:32
@JelleZijlstra
pythongh-104799: Move location of type_params AST fields
81d8dd8
@JelleZijlstra
class not type
bd6bd41
@JelleZijlstra
Default missing AST lists to the empty list
509fc7a
@bedevere-bot bedevere-bot mentioned this pull request May 24, 2023
PEP-695: Potentially breaking changes made to __match_args__ attributes of AST nodes #104799
Closed
@JelleZijlstra

JelleZijlstra commented May 24, 2023

Copy link
Copy Markdown
Member Author

(This PR is on top of the changes from #104828.)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

AlexWaygood and others added 2 commits May 24, 2023 09:19
@AlexWaygood
Merge branch 'main' into defaultempty
803c2f1
@JelleZijlstra
Merge branch 'main' into defaultempty
6d316c0
@JelleZijlstra
JelleZijlstra marked this pull request as ready for review May 25, 2023 02:47
@JelleZijlstra
JelleZijlstra requested review from isidentical, lysnikolaou and pablogsal as code owners May 25, 2023 02:47
@bedevere-bot bedevere-bot added the awaiting core review label May 25, 2023
@JelleZijlstra

JelleZijlstra commented May 25, 2023

Copy link
Copy Markdown
Member Author

Ideally I'd like this to go into 3.12 to fix the BC issues in #104799, but maybe it's too late.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@markshannon

markshannon commented May 31, 2023

Copy link
Copy Markdown
Member

So I understand correctly, this changes the representation of a missing list from NULL to PyList_New(0). Correct?

I am a little concerned (just a little) about the performance implications.
Which nodes will this affect in practice?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JelleZijlstra
Merge remote-tracking branch 'upstream/main' into defaultempty
befa1c8
@JelleZijlstra

JelleZijlstra commented May 31, 2023

Copy link
Copy Markdown
Member Author

So I understand correctly, this changes the representation of a missing list from NULL to PyList_New(0). Correct?

No, it changes from raising a TypeError to PyList_New(0). This is easier to see in the generated code than in the code generator:

@@ -9306,10 +9404,12 @@ obj2ast_expr(struct ast_state *state, PyObject* obj, expr_ty* out, PyArena*
             return 1;
         }
         if (tmp == NULL) {
-            PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp");
-            return 1;
+            tmp = PyList_New(0);
+            if (tmp == NULL) {
+                return 1;
+            }
         }
-        else {
+        {
             int res;
             Py_ssize_t len;
             Py_ssize_t i;

So this shouldn't affect performance for code that was already working.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JelleZijlstra
blurb
bee54d8
@JelleZijlstra
JelleZijlstra merged commit 77d2579 into python:main Jun 2, 2023
@bedevere-bot bedevere-bot removed the awaiting core review label Jun 2, 2023
@JelleZijlstra
JelleZijlstra deleted the defaultempty branch June 2, 2023 01:39
@JelleZijlstra JelleZijlstra added the needs backport to 3.12 only security fixes label Jun 2, 2023
@miss-islington

miss-islington commented Jun 2, 2023

Copy link
Copy Markdown
Contributor

Thanks @JelleZijlstra for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jun 2, 2023
@JelleZijlstra @AlexWaygood @miss-islington
pythongh-104799: Default missing lists in AST to the empty list (pyth…
85e328a
…onGH-104834)

(cherry picked from commit 77d2579)

Co-authored-by: Jelle Zijlstra <[email protected]>
Co-authored-by: Alex Waygood <[email protected]>
@bedevere-bot

bedevere-bot commented Jun 2, 2023

Copy link
Copy Markdown

GH-105213 is a backport of this pull request to the 3.12 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the needs backport to 3.12 only security fixes label Jun 2, 2023
JelleZijlstra added a commit that referenced this pull request Jun 2, 2023
@miss-islington @JelleZijlstra @AlexWaygood
[3.12] gh-104799: Default missing lists in AST to the empty list (GH-…
e6d5e63
…104834) (#105213)

(cherry picked from commit 77d2579)

Co-authored-by: Jelle Zijlstra <[email protected]>
Co-authored-by: Alex Waygood <[email protected]>
@erlend-aasland erlend-aasland mentioned this pull request Jun 6, 2023
3.12 backport gh 105236 #105358
Closed
@DavidCEllis DavidCEllis mentioned this pull request Jun 7, 2023
3.12 Test failing due to change in FunctionDef creation - Should be fixed in 3.12.0-beta2 DavidCEllis/PrefabClasses#67
Closed
@JelleZijlstra
JelleZijlstra restored the defaultempty branch September 10, 2024 23:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@isidentical isidentical Awaiting requested review from isidentical
@pablogsal pablogsal Awaiting requested review from pablogsal pablogsal is a code owner
@lysnikolaou lysnikolaou Awaiting requested review from lysnikolaou lysnikolaou is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@JelleZijlstra @markshannon @miss-islington @bedevere-bot @AlexWaygood
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.