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

Merge branch 'master' into enums #1

Merged
merged 40 commits into from
Feb 7, 2023
Merged

Conversation

leogama
Copy link

@leogama leogama commented Aug 6, 2022

What I basically did was:

Tests are passing for Python 3.7, PyPy 3.7 and Python 3.11b5 on my machine.

anivegesana and others added 30 commits June 7, 2022 05:36
* Support PyCapsule

* Import PyCapsule if it already exists and add descriptive warnings

* Suggestions from code review

* Update copyright
…l"` (uqfoundation#490)

I'm tracing some problems with my "portable" mode prototype and hit a bug with references the `_dill` submodule saved as global:

```python
>>> import dill
>>> dill.dumps(dill._dill, 0)
b'cdill._shims\n_dill\np0\n.'
```
The `_dill` submodule is saved as an attribute of the `dill._shims` submodule, which is valid, but it should be just `dill._dill`.

The `_dill` submodule is special-cased to be saved as global:
https://github.com/uqfoundation/dill/blob/8e5e450b9ed8dff164fc259c468365e2235c6581/dill/_dill.py#L1807-L1810

But `pickle.whichmodule` misidentifies it as pertaining to `dill._shims`, because this entry is set earlier in `sys.modules` and it picks the first match.

---

The change fixes things for this especial case, but there is potential for new bugs related to other submodules:
```python
>>> import dill, glob, importlib, os, pickle, pprint
>>> os.chdir(dill.__path__[0])
>>> modules = [mod.rpartition('.')[0] for mod in glob.glob('*py') if not mod.startswith('__')]
>>> modules = {mod: importlib.import_module('dill.' + mod) for mod in modules}
>>> pprint.pprint({name: pickle.whichmodule(mod, name) for name, mod in modules.items()})
{'_dill': 'dill._shims',
 '_objects': 'dill',
 '_shims': 'dill._dill',
 'detect': 'dill',
 'objtypes': 'dill',
 'pointers': 'dill',
 'settings': '__main__',
 'source': 'dill',
 'temp': 'dill'}
```
Note how `_shims` is attributed to `dill._dill` and `settings` is attributed to `__main__`(???). But currently they are not saved as globals.
* Create a soft_def shim to combine move_to and Getattr

* Rename `soft_def` to `register_shim`
* Incidental implementation specific types

* Add incedental types to objects.py

* Remove types for objects that are automatically by Python

* Rename `SymtableStentryType` to `SymtableEntryType`
This is a very strange use case of functions and methods that Python's 
pickle package doesn't handle correctly (uqfoundation#510). This case used to work 
in pre-0.3.5 dill, so let's bring back the old dill implementation.

The comments are irrelevant in Python 3.
correct failures,  registered, and succeeds
…vel (uqfoundation#471)

* Add detailed trace mode showing dumped object size and visual depeth level

* Tests: logging code coverage

* logger: just show size after writing object

* Box drawing formatting

* fallback for non-UTF-8 terminals

* review: corrections and improvements

* review: adjustments

* split module imports into separated lines

* deal with non-standardized UTF-8 encoding name

* update sample trace in module docs

* use trace() as a context manager

* pypy special cases

* accept file handle in trace context manager

* fix dict (PyPy) and mappingproxy (CPython) trace

Co-authored-by: anivegesana <anirudh.vegesana@gmail.com>
* Kickstart support drop for Python < 3.7

Step 1 of code clean-up: mechanically remove if-else branches that would never
run in Python/PyPy >= 3.7.  There's still some unused or redundant code, left
for the next step to facilitate review.

Note: all the remaining `sys.hexversion` tests were standardized to use
numerical comparison and hexadecimal integer literals (e.g. `0x30b00a7` for
version 3.11.0a7) as most of them already were.

* convert single function defined via exec() due to Python2/3 differences

* drop 'from __future__ import print_function' statements

* remove conditional imports due to Python 2 and old Python 3

* substitute bare 'except' clauses by 'except Exception' or more specific where it's obvious

* split module imports into separated lines

* idem, but for test files

* review: adjustments

* tests: get a default Python 3 executable

* update module docs

* update README

* review: corrections

* remove unicode prefix from strings in docs/source/conf.py
…uples) (uqfoundation#496)

* rewrite _create_code() with Structural Pattern Matching (limited to tuples)

* lnotab and linetable: fixup

* pattern matching: optimizations

* pattern matching: more optimizations

* _create_code: tests

* match/case: don't check code members' types
As things stand, the tests never fail when run via tox.
`__main__.py` runs each individual test script, but always exits
0, even if a test script exits >0.

Signed-off-by: Adam Williamson <awilliam@redhat.com>
…le (uqfoundation#507)

* Don't update vars(main) twice

* Inspect the pickle beginnig to identify main and check against 'main' argument

* Save and restore modules created at runtime with ModuleType()

* tests: don't need to add runtime module to sys.modules

* load_session_copy(): load a session state into a runtime module

* tests: session tests code reorganization

* tests: test runtime created module session saving

* tests: test load_session_copy

* review: adjustments

* small fixes

* use __dict__

* naming changes

* review: final renaming and adjustments
…ndation#526)

* fix dump_module() bugs and rename parameter 'main' to 'module' (fixes uqfoundation#525)

New phrasing of mismatching modules error messages in load_session():

```python
>>> import dill
>>> dill.dump_module()
>>> dill.load_module(module='math')
ValueError: can't update module 'math' with the saved state of module '__main__'

>>> import types
>>> main = types.ModuleType('__main__')
>>> dill.load_module(module=main)
ValueError: can't update module-type object '__main__' with the saved state of imported module '__main__'

>>> dill.dump_module(module=main)
>>> dill.load_module(module='__main__')
ValueError: can't update imported module '__main__' with the saved state of module-type object '__main__'
```

* dump_module: clarify refimport description

* improvements to 'refimported' handling and extra checks in *_module() functions

* load_session(): clarify that the 'module' argument must match the session file's module
…qfoundation#503)

* A temporary quick fix for dataclass serialization (uqfoundation#500)

This quick fix will be removed when proper dataclass serialization 
support is added to dill. This is just here to allow for better support, 
at least for now. dataclasses pickled with this PR will be unpicklable 
by future versions of dill, but the future versions of dill will be able 
to be automatically use the newer features in dataclasses.py that were 
not available in older versions of Python. That forward compatibility 
features is not present in this PR.

* Fix bug in pickling MappingProxyType in PyPy 3.7+
mmckerns and others added 10 commits July 21, 2022 19:40
* move session-related code to new session module

* export objects to ._dill for compatibility with 0.3.5.1

* use dill._dill.__builtin__ instead of builtins for consistency
…oundation#346) (uqfoundation#531)

* Temporary quick fix getsource() on IPython interpreter (fixes uqfoundation#346)

* minor changes
…ion#529)

* fix KeyError when pickling type with '__dict__' or '__weakref__' in '__slots__'

* fix KeyError when pickling a type where '__slots__' is a string
@anivegesana anivegesana merged commit 1518988 into anivegesana:enums Feb 7, 2023
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.

4 participants