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

对字典对象执行深度拷贝时引发 pickle 异常 #9

Open
2018-11-27 opened this issue Apr 29, 2023 · 2 comments
Open

对字典对象执行深度拷贝时引发 pickle 异常 #9

2018-11-27 opened this issue Apr 29, 2023 · 2 comments
Assignees
Labels
enhancement New feature or request Processed

Comments

@2018-11-27
Copy link
Member

2018-11-27 commented Apr 29, 2023

一个很常见的,Python中个别对象不可 pickle 的问题。

@2018-11-27 2018-11-27 added the enhancement New feature or request label Apr 29, 2023
@2018-11-27 2018-11-27 self-assigned this Apr 29, 2023
@2018-11-27
Copy link
Member Author

新增一个专用于字典对象深度拷贝的方法 gdict.deepcopy,仅拷贝字典内层的容器类对象,这样做可绝对跳过无法被 pickle 的对象。
(往往我们的代码在执行深度拷贝时逻辑上都是不需要拷贝内层的非容器类对象的)

2018-11-27 added a commit that referenced this issue Apr 29, 2023
1.Optimize logical blocks for real code imports.
2.Optimize the `gdict` core again (initialization process). (A new `gdict` instance is created whether or not it is already a `gdict` instance.)
3.Perfectly solves the problem of not being able to `pickle` some instances when calling `copy.deepcopy` in the `gdict` instances (add new method `deepcopy`, incomplete deep copy, only copy internal container class instances). issue: #9.
4.Directly modified the parameter name of the `deep` series methods `keypath` -> `deepkey` (no warning, no compatibility processing, rest assured there will be few compatibility issues).
5.In `deepget`, no longer use the `eval` function to try to evaluate for special `key` (because `eval` is too slow), use the `elif` continuous statement instead.
6.Update the readme file, and open source library description information on PyPi.

1.优化真实代码导入的逻辑块。
2.再度优化 `gdict` 核心(初始化过程),无论是否已经是 `gdict` 实例,都会创建新的 `gdict` 实例。
3.在 `gdict` 实例中完美解决了在调用 `copy.deepcopy` 时个别实例无法被 `pickle` 的问题(新增方法 `deepcopy`,不完全深度拷贝,仅拷贝内部的容器类实例)。问题: https://github.com/gqylpy/gqylpy-dict/issues/9。
4.直接修改了 `deep` 系列方法的参数名称 `keypath` -> `deepkey`(没有警告,也没有做任何兼容,放心几乎不会有兼容性问题)。
5.在 `deepget` 中,针对特殊的 `key` 不再使用 `eval` 函数尝试取值(因为 `eval` 太慢了),改为使用 `elif` 连续语句。
6.更新自述文件和PyPi上的开源库简述信息。
@2018-11-27
Copy link
Member Author

2018-11-27 commented Apr 29, 2023

1.2.1 版本已解决,commit

     def deepcopy(self) -> 'gdict':
        """
        Incomplete deep copy, NOTE not the same as `copy.deepcopy`!

        Copy only the instances of container types (only instances of `gdict`,
        `dict`, `list` and `tuple`).
        """
        return gdict(self)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Processed
Projects
None yet
Development

No branches or pull requests

1 participant