I liked your idea so much back when you suggested it that I implemented it
in our sitecustomize.py back when we were using 3.8, and added a check to
our lint tools to require that the 'strict=' parameter be present in all
uses of 'zip'.  We found a couple of silent bugs almost immediately, so
thank you!

On Thu, Dec 1, 2022 at 11:38 AM Ram Rachum <r...@rachum.com> wrote:

> Reviving this thread 2.5 years after I started it just to share this
> satisfying moment. I was just spending a few hours furiously coding on my
> research <https://r.rachum.com/> using Python 3.10, and when I ran my
> code I got this traceback:
>
>   File
> "/home/ramrachum/.venvs/ray_env/lib/python3.10/site-packages/ray/rllib/algorithms/algorithm.py",
> line 1993, in log_result
>     self.callbacks.on_train_result(algorithm=self, result=result)
>     │                                        │            └
> {'custom_metrics': {}, 'episode_media': {}, 'num_recreated_workers': 0,
> 'info': {'learner': {'policy_robot': {'learner_stats': {...
>     │                                        └ PPO
>     └ PPO
>   File "/herring/nichos/nichos/snare/__init__.py", line 150, in
> on_train_result
>     robot_move_by_state = get_move_by_state(
>   File "/herring/nichos/nichos/snare/__init__.py", line 75, in
> get_move_by_state
>     return dict(zip(states, moves, strict=True))
>                     │       └ array([0, 1, 0, ..., 1, 0, 1])
>                     └ <itertools.chain object at 0x7f08dc157610>
> ValueError: zip() argument 2 is longer than argument 1
>
> It took a few seconds for me to understand... "Ah... This error is my
> error" :)
>
>
> On Mon, Apr 20, 2020 at 8:42 PM Ram Rachum <r...@rachum.com> wrote:
>
>> Here's something that would have saved me some debugging yesterday:
>>
>>     >>> zipped = zip(x, y, z, strict=True)
>>
>> I suggest that `strict=True` would ensure that all the iterables have
>> been exhausted, raising an exception otherwise.
>>
>> This is useful in cases where you're assuming that the iterables all have
>> the same lengths. When your assumption is wrong, you currently just get a
>> shorter result, and it could take you a while to figure out why it's
>> happening.
>>
>> What do you think?
>>
> _______________________________________________
> Python-ideas mailing list -- python-ideas@python.org
> To unsubscribe send an email to python-ideas-le...@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-ideas@python.org/message/DPQEIIOAEGJKIVDHTAKQ6CJPCGS7C5G7/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/ZI5CDH3M66MPHNQK3UJVWAF77VG7JVJC/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to