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

deepcopy with betterproto.Enum fields fails #567

Closed
3 tasks done
atomicmac opened this issue Mar 27, 2024 · 2 comments
Closed
3 tasks done

deepcopy with betterproto.Enum fields fails #567

atomicmac opened this issue Mar 27, 2024 · 2 comments
Labels
bug Something isn't working investigation needed

Comments

@atomicmac
Copy link
Contributor

atomicmac commented Mar 27, 2024

Summary

Using deepcopy on a mesage with a betterproto.Enum fields fails

Reproduction Steps

Create a message that has a betterproto.Enum nested in its hierarchy somewhere.
Execute copy.deepcopy on the message.

Expected Results

A deep copy of the message

Actual Results

A TypeError occurs when the Enum's new is invoked by copy._reconstruct

Screenshot from 2024-03-27 11-29-44

/home/user/.pyenv/versions/3.11.4/lib/python3.11/copy.py:153: in deepcopy
    y = copier(memo)
/home/user/.pyenv/versions/3.11.4/lib/python3.11/site-packages/betterproto/__init__.py:882: in __deepcopy__
    kwargs[name] = deepcopy(value)
/home/user/.pyenv/versions/3.11.4/lib/python3.11/copy.py:153: in deepcopy
    y = copier(memo)
/home/user/.pyenv/versions/3.11.4/lib/python3.11/site-packages/betterproto/__init__.py:882: in __deepcopy__
    kwargs[name] = deepcopy(value)
/home/user/.pyenv/versions/3.11.4/lib/python3.11/copy.py:146: in deepcopy
    y = copier(x, memo)
/home/user/.pyenv/versions/3.11.4/lib/python3.11/copy.py:206: in _deepcopy_list
    append(deepcopy(a, memo))
/home/user/.pyenv/versions/3.11.4/lib/python3.11/copy.py:153: in deepcopy
    y = copier(memo)
/home/user/.pyenv/versions/3.11.4/lib/python3.11/site-packages/betterproto/__init__.py:882: in __deepcopy__
    kwargs[name] = deepcopy(value)
/home/user/.pyenv/versions/3.11.4/lib/python3.11/copy.py:153: in deepcopy
    y = copier(memo)
/home/user/.pyenv/versions/3.11.4/lib/python3.11/site-packages/betterproto/__init__.py:882: in __deepcopy__
    kwargs[name] = deepcopy(value)
/home/user/.pyenv/versions/3.11.4/lib/python3.11/copy.py:153: in deepcopy
    y = copier(memo)
/home/user/.pyenv/versions/3.11.4/lib/python3.11/site-packages/betterproto/__init__.py:882: in __deepcopy__
    kwargs[name] = deepcopy(value)
/home/user/.pyenv/versions/3.11.4/lib/python3.11/copy.py:153: in deepcopy
    y = copier(memo)
/home/user/.pyenv/versions/3.11.4/lib/python3.11/site-packages/betterproto/__init__.py:882: in __deepcopy__
    kwargs[name] = deepcopy(value)
/home/user/.pyenv/versions/3.11.4/lib/python3.11/copy.py:172: in deepcopy
    y = _reconstruct(x, memo, *rv)
/home/user/.pyenv/versions/3.11.4/lib/python3.11/copy.py:265: in _reconstruct
    y = func(*args)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

cls = <enum 'PixelFormat'>, args = (1,)

    def __newobj__(cls, *args):
>       return cls.__new__(cls, *args)
E       TypeError: Enum.__new__() takes 1 positional argument but 2 were given

/home/user/.pyenv/versions/3.11.4/lib/python3.11/copyreg.py:105: TypeError

I thought this error could be the result of python/cpython#106602 but I upgraded to 3.11.8 and see the same behavior. It looks like betterproto.Enum misses out on the enum.Enum.deepcopy and copy methods because it does not inherit directly from enum.Enum

System Information

Python 3.11.8
Name: betterproto
Version: 2.0.0b6
Summary: A better Protobuf / gRPC generator & library
Home-page: https://github.com/danielgtaylor/python-betterproto
Author: Daniel G. Taylor
Author-email: danielgtaylor@gmail.com
License: MIT
Location: /home/user/.pyenv/versions/3.11.8/envs/ampcv-3.11.8/lib/python3.11/site-packages
Requires: grpclib, python-dateutil, typing-extensions

Checklist

  • I have searched the issues for duplicates.
  • I have shown the entire traceback, if possible.
  • I have verified this issue occurs on the latest prelease of betterproto which can be installed using pip install -U --pre betterproto, if possible.
@atomicmac atomicmac added bug Something isn't working investigation needed labels Mar 27, 2024
@atomicmac
Copy link
Contributor Author

I created a pull request to fix this #566

@atomicmac
Copy link
Contributor Author

Pull request #566 is merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working investigation needed
Projects
None yet
Development

No branches or pull requests

1 participant