FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-104799: Default missing lists in AST to the empty list by JelleZijlstra · Pull Request #104834 · python/cpython · GitHub

/ cpython Public

gh-104799: Default missing lists in AST to the empty list - #104834

Merged
JelleZijlstra merged 7 commits into
python:mainfrom
JelleZijlstra:defaultempty
Jun 2, 2023
Merged

gh-104799: Default missing lists in AST to the empty list#104834
JelleZijlstra merged 7 commits into
python:mainfrom
JelleZijlstra:defaultempty

Conversation

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

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.


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

Copy link
Copy Markdown
Member Author

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

JelleZijlstra marked this pull request as ready for review May 25, 2023 02:47

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.

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?

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.

JelleZijlstra merged commit 77d2579 into python:main Jun 2, 2023
JelleZijlstra deleted the defaultempty branch June 2, 2023 01:39
JelleZijlstra added the needs backport to 3.12 only security fixes label Jun 2, 2023

Copy link
Copy Markdown
Contributor

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

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jun 2, 2023
…onGH-104834)

(cherry picked from commit 77d2579)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>

Copy link
Copy Markdown

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

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
…104834) (#105213)

(cherry picked from commit 77d2579)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
JelleZijlstra restored the defaultempty branch September 10, 2024 23:37
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants


Back | FazBrowse Home | New Git URL