| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
Sync the remote fork with upstream and pull to local branch
|
Search for HAS_DICT in the same file and add it to Chain's flags annotation. |
Sorry, something went wrong.
|
I added HAS_DICT and now the problem seems to be that when a deepcopy operation is performed on a chain object it appears empty. I was thinking that it might iterate through the values somewhere where it shouldn't and at the same time "clears" them. How it works with Python 3: >>> import copy
>>> from itertools import chain
>>> oper = copy.deepcopy
>>> it = chain('abc', 'def')
>>> res = oper(it)
>>> list(res)
['a', 'b', 'c', 'd', 'e', 'f']
>>>
How it works with this implementation: >>>>> import copy
>>>>> from itertools import chain
>>>>> oper = copy.deepcopy
>>>>> it = chain('abc', 'def')
>>>>> res = oper(it)
>>>>> list(res)
[]
>>>>>
|
Sorry, something went wrong.
|
The solution was to implement setstate for chain. This will also solve #3779 I think. |
Sorry, something went wrong.
|
@Snowapril you may be interested in this |
Sorry, something went wrong.
There was a problem hiding this comment.
Looks good! I left a few suggestions about style and locks.
Sorry, something went wrong.
| match source { | ||
| Some(source) => match active { | ||
| Some(active) => { | ||
| Ok(vm.new_tuple((cls, vm.ctx.empty_tuple.clone(), (source, active)))) | ||
| } | ||
| None => Ok(vm.new_tuple((cls, vm.ctx.empty_tuple.clone(), (source,)))), | ||
| }, | ||
| None => Ok(vm.new_tuple((cls, vm.ctx.empty_tuple.clone()))), | ||
| } |
There was a problem hiding this comment.
| match source { | |
| Some(source) => match active { | |
| Some(active) => { | |
| Ok(vm.new_tuple((cls, vm.ctx.empty_tuple.clone(), (source, active)))) | |
| } | |
| None => Ok(vm.new_tuple((cls, vm.ctx.empty_tuple.clone(), (source,)))), | |
| }, | |
| None => Ok(vm.new_tuple((cls, vm.ctx.empty_tuple.clone()))), | |
| } | |
| let empty_tuple = vm.ctx.empty_tuple.clone(); | |
| let reduced = match source { | |
| Some(source) => match active { | |
| Some(active) => vm.new_tuple((cls, empty_tuple, (source, active))), | |
| None => vm.new_tuple((cls, empty_tuple, (source,))), | |
| }, | |
| None => vm.new_tuple((cls, empty_tuple)), | |
| }; | |
| Ok(reduced) |
Sorry, something went wrong.
| *zelf.source.write() = source.to_owned().try_into_value(vm)?; | ||
| *zelf.active.write() = active.to_owned().try_into_value(vm)?; |
There was a problem hiding this comment.
To avoid unpleasure broken synchronization, locking both and writing will be better.
| *zelf.source.write() = source.to_owned().try_into_value(vm)?; | |
| *zelf.active.write() = active.to_owned().try_into_value(vm)?; | |
| let mut source_lock = zelf.source.write(); | |
| let mut active_lock = zelf.active.write(); | |
| *source_lock = source.to_owned().try_into_value(vm)?; | |
| *active_lock = active.to_owned().try_into_value(vm)?; |
Sorry, something went wrong.
|
Thank you for contributing! |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Hello!
I tried to implement the reduce method for PyItertoolsChain (issue #3611) but got stuck. I used the CPython implementation as a reference. The implementation seems to work just fine with simple arrays etc. but fails the test_chain_reducible test. Any suggestions on why?
The error message:
ERROR: test_chain_reducible (test.test_itertools.TestBasicOps) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/dan/Projects/RustPython/pylib/Lib/test/test_itertools.py", line 187, in test_chain_reducible self.assertEqual(list(oper(it)), list('abcdef')) File "/home/dan/Projects/RustPython/pylib/Lib/copy.py", line 172, in deepcopy y = _reconstruct(x, memo, *rv) File "/home/dan/Projects/RustPython/pylib/Lib/copy.py", line 279, in _reconstruct y.__dict__.update(state) AttributeError: 'chain' object has no attribute '__dict__' ----------------------------------------------------------------------