Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-90104: avoid RecursionError on recursive dataclass field repr #100756

Merged
merged 4 commits into from
Jan 6, 2023

Conversation

carljm
Copy link
Member

@carljm carljm commented Jan 4, 2023

Copy link
Contributor

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

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

Thank you!

rec_field.type = rec_field
rec_field.name = "id"
repr_output = repr(rec_field)
expected_output = "Field(name='id',type=...," \
Copy link
Member

Choose a reason for hiding this comment

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

I think I'd just test that "type=..." is in the repr, not for the rest of the values. If new ones are added, this test would need to be modified.

Also, I think an additional test for the original problem:

@dataclass
class D:
    C: C = field()

would be good.

Otherwise looks good!

Copy link
Member

Choose a reason for hiding this comment

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

And to be clear: I'd just add the second test to make sure it doesn't raise RecursionError, I wouldn't go nuts on testing the exact output.

Copy link
Member Author

Choose a reason for hiding this comment

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

Let me know if the assertion in the new test qualifies as "going nuts" -- just seemed easy to check, and more confusing to have a test with no assertions at all.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe "go nuts" wasn't the best wording to use 😃. Your change is exactly what I would have done, down to the commas, so I think it's perfect. Thanks!

carljm added 2 commits January 5, 2023 07:18
* main:
  pythonGH-100288: Remove LOAD_ATTR_METHOD_WITH_DICT instruction. (pythonGH-100753)
  pythonGH-100766: Note that locale.LC_MESSAGES is not universal (pythonGH-100702)
  Drop myself from pathlib maintenance (python#100757)
  pythongh-100739: Respect mock spec when checking for unsafe prefixes (python#100740)
@ericvsmith ericvsmith merged commit 0a7936a into python:main Jan 6, 2023
@miss-islington
Copy link
Contributor

Thanks @carljm for the PR, and @ericvsmith for merging it 🌮🎉.. I'm working now to backport this PR to: 3.10, 3.11.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

Sorry, @carljm and @ericvsmith, I could not cleanly backport this to 3.11 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker 0a7936a38f0bab1619ee9fe257880a51c9d839d5 3.11

@miss-islington
Copy link
Contributor

Sorry @carljm and @ericvsmith, I had trouble checking out the 3.10 backport branch.
Please retry by removing and re-adding the "needs backport to 3.10" label.
Alternatively, you can backport using cherry_picker on the command line.
cherry_picker 0a7936a38f0bab1619ee9fe257880a51c9d839d5 3.10

@bedevere-bot
Copy link

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot ARM Raspbian 3.x has failed when building commit 0a7936a.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/all/#builders/424/builds/3235) and take a look at the build logs.
  4. Check if the failure is related to this commit (0a7936a) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/all/#builders/424/builds/3235

Summary of the results of the build (if available):

== Tests result: ENV CHANGED ==

411 tests OK.

10 slowest tests:

  • test_venv: 6 min 48 sec
  • test_largefile: 6 min 47 sec
  • test_multiprocessing_spawn: 4 min 44 sec
  • test_concurrent_futures: 3 min 16 sec
  • test_ctypes: 3 min 13 sec
  • test_zipfile: 3 min 3 sec
  • test_asyncio: 2 min 53 sec
  • test_pyclbr: 2 min 40 sec
  • test_multiprocessing_forkserver: 1 min 57 sec
  • test_tokenize: 1 min 54 sec

1 test altered the execution environment:
test_multiprocessing_fork

21 tests skipped:
test_check_c_globals test_devpoll test_idle test_ioctl test_kqueue
test_launcher test_msilib test_peg_generator test_perf_profiler
test_startfile test_tcl test_tix test_tkinter test_ttk
test_ttk_textonly test_turtle test_winconsoleio test_winreg
test_winsound test_wmi test_zipfile64

Total duration: 30 min 7 sec

Click to see traceback logs
remote: Enumerating objects: 11, done.        
remote: Counting objects:  10% (1/10)        
remote: Counting objects:  20% (2/10)        
remote: Counting objects:  30% (3/10)        
remote: Counting objects:  40% (4/10)        
remote: Counting objects:  50% (5/10)        
remote: Counting objects:  60% (6/10)        
remote: Counting objects:  70% (7/10)        
remote: Counting objects:  80% (8/10)        
remote: Counting objects:  90% (9/10)        
remote: Counting objects: 100% (10/10)        
remote: Counting objects: 100% (10/10), done.        
remote: Compressing objects:  11% (1/9)        
remote: Compressing objects:  22% (2/9)        
remote: Compressing objects:  33% (3/9)        
remote: Compressing objects:  44% (4/9)        
remote: Compressing objects:  55% (5/9)        
remote: Compressing objects:  66% (6/9)        
remote: Compressing objects:  77% (7/9)        
remote: Compressing objects:  88% (8/9)        
remote: Compressing objects: 100% (9/9)        
remote: Compressing objects: 100% (9/9), done.        
remote: Total 11 (delta 1), reused 2 (delta 1), pack-reused 1        
From https://github.com/python/cpython
 * branch                  main       -> FETCH_HEAD
Note: switching to '0a7936a38f0bab1619ee9fe257880a51c9d839d5'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at 0a7936a38f gh-90104: avoid RecursionError on recursive dataclass field repr (gh-100756)
Switched to and reset branch 'main'

Objects/obmalloc.c:776:1: warning: ‘always_inline’ function might not be inlinable [-Wattributes]
  776 | arena_map_get(pymem_block *p, int create)
      | ^~~~~~~~~~~~~

make: *** [Makefile:1906: buildbottest] Error 3

@carljm
Copy link
Member Author

carljm commented Jan 6, 2023

On the failing buildbot, test_multiprocessing_fork left behind a temporary file. That seems pretty likely a false positive, doesn't seem like it could be caused by this PR.

@carljm
Copy link
Member Author

carljm commented Jan 6, 2023

I'll put up manual backport PRs since the auto-backporting failed.

@ericvsmith
Copy link
Member

I'll put up manual backport PRs since the auto-backporting failed.

Thanks. I had started looking at doing this, but I'm having some issue with cherry_picker. I'm sure I'm doing something stupid.

On the failing buildbot, test_multiprocessing_fork left behind a temporary file. That seems pretty likely a false positive, doesn't seem like it could be caused by this PR.

Agreed.

@bedevere-bot
Copy link

GH-100784 is a backport of this pull request to the 3.11 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.11 only security fixes label Jan 6, 2023
carljm added a commit to carljm/cpython that referenced this pull request Jan 6, 2023
…eld repr (pythongh-100756)

Avoid RecursionError on recursive dataclass field repr

(cherry picked from commit 0a7936a)
@bedevere-bot
Copy link

GH-100785 is a backport of this pull request to the 3.10 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.10 only security fixes label Jan 6, 2023
miss-islington pushed a commit that referenced this pull request Jan 6, 2023
…pr (gh-100756) (GH-100784)

Avoid RecursionError on recursive dataclass field repr

(cherry picked from commit 0a7936a)

Automerge-Triggered-By: GH:ericvsmith
miss-islington pushed a commit that referenced this pull request Jan 6, 2023
…pr (gh-100756) (GH-100785)

Avoid RecursionError on recursive dataclass field repr

(cherry picked from commit 0a7936a)

Automerge-Triggered-By: GH:ericvsmith
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.

RecursionError when annotating a field with the same name as a field
5 participants