Open nitzmahone opened 3 weeks ago
I've been confused by that code as well. If the comment isn't accurate and everything still works, I'm fine with a PR for that.
Cool- there's another small related issue + fix inbound that we tripped over while writing the tests for this one (my colleague is filing a separate issue + PR right now).
Description
Due to an ancient erroneous deletion of
__slots__
metadata, it's not possible to copy/deepcopy/pickleUndefined
objects (all of which we occasionally need to do in Ansible) in Python > 3.5.The comment above the deletion of
__slots__
implies a misunderstanding of how that metadata was/is used. The deletion was always probably technically a bug, but once Python started providing default implementations of__getstate__
and__reduce_ex__
on all objects (which consult that metadata at runtime), it broke the default copyability/pickle-ability ofUndefined
(and derived) objects.We're working around this with a monkeypatch that restores the missing
__slots__
metadata. We've also submitted PR #2026 to zap the problematic deletion and tests that verify copy/deepcopy/pickle functionality on all the built-inUndefined
types.Repro
(on any Python > 3.5 with Jinja installed):
Expected
The default runtime-provided implementations of
__getstate__
and__reduce_ex__
that backcopy.copy
,copy.deepcopy
andpickle
should work properly with allUndefined
derived types.Environment