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

Proper way to deeply copy a Wikicode object #317

Open
avidspartan1 opened this issue Feb 11, 2024 · 2 comments
Open

Proper way to deeply copy a Wikicode object #317

avidspartan1 opened this issue Feb 11, 2024 · 2 comments

Comments

@avidspartan1
Copy link

Hi! I'm curious as to the "proper" way to deeply copy a Wikicode object.

So far, I've been using the copy module's deepcopy method successfully, although recently I ran into a recursion error (stacktrace abbreviated):

  ...
  File "C:\Users\pdhoi\AppData\Local\Programs\Python\Python310\lib\copy.py", line 231, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "C:\Users\pdhoi\AppData\Local\Programs\Python\Python310\lib\copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "C:\Users\pdhoi\AppData\Local\Programs\Python\Python310\lib\copy.py", line 271, in _reconstruct
    state = deepcopy(state, memo)
  File "C:\Users\pdhoi\AppData\Local\Programs\Python\Python310\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Users\pdhoi\AppData\Local\Programs\Python\Python310\lib\copy.py", line 231, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "C:\Users\pdhoi\AppData\Local\Programs\Python\Python310\lib\copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "C:\Users\pdhoi\AppData\Local\Programs\Python\Python310\lib\copy.py", line 288, in _reconstruct
    item = deepcopy(item, memo)
  File "C:\Users\pdhoi\AppData\Local\Programs\Python\Python310\lib\copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "C:\Users\pdhoi\AppData\Local\Programs\Python\Python310\lib\copy.py", line 271, in _reconstruct
    state = deepcopy(state, memo)
  File "C:\Users\pdhoi\AppData\Local\Programs\Python\Python310\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Users\pdhoi\AppData\Local\Programs\Python\Python310\lib\copy.py", line 231, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "C:\Users\pdhoi\AppData\Local\Programs\Python\Python310\lib\copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "C:\Users\pdhoi\AppData\Local\Programs\Python\Python310\lib\copy.py", line 271, in _reconstruct
    state = deepcopy(state, memo)
  File "C:\Users\pdhoi\AppData\Local\Programs\Python\Python310\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Users\pdhoi\AppData\Local\Programs\Python\Python310\lib\copy.py", line 231, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "C:\Users\pdhoi\AppData\Local\Programs\Python\Python310\lib\copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "C:\Users\pdhoi\AppData\Local\Programs\Python\Python310\lib\copy.py", line 288, in _reconstruct
    item = deepcopy(item, memo)
  File "C:\Users\pdhoi\AppData\Local\Programs\Python\Python310\lib\copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "C:\Users\pdhoi\AppData\Local\Programs\Python\Python310\lib\copy.py", line 271, in _reconstruct
    state = deepcopy(state, memo)
  File "C:\Users\pdhoi\AppData\Local\Programs\Python\Python310\lib\copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "C:\Users\pdhoi\AppData\Local\Programs\Python\Python310\lib\copy.py", line 231, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "C:\Users\pdhoi\AppData\Local\Programs\Python\Python310\lib\copy.py", line 137, in deepcopy
    d = id(x)
RecursionError: maximum recursion depth exceeded while calling a Python object

One thought was to raise the recursion limit, but I thought I'd post here first to see if there's a better way to deeply copy a Wikicode object.

@avidspartan1 avidspartan1 changed the title Proper way to copy a Wikicode object Proper way to deeply copy a Wikicode object Feb 11, 2024
@earwig
Copy link
Owner

earwig commented Feb 12, 2024

Hi! I don't have an answer aside from copy.deepcopy. What is the use case, out of curiosity?

The only ways I can see the recursion error happening are if the wikicode is extremely deeply nested (but this shouldn't be possible normally since the parser has a much lower recursion limit than Python) or if a node was somehow made a child of one of its ancestors.

Can you share the code/wikitext?

@matkoniecz
Copy link

@avidspartan1 Can you share the code/wikitext triggering this?

(if not I think it can be safely closed)

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

No branches or pull requests

3 participants