On Mon, Aug 17, 2020 at 8:11 AM Mark Shannon <m...@hotpy.org> wrote: > > > On 17/08/2020 3:08 pm, Henk-Jaap Wagenaar wrote: > > Thanks for having a look! The example now looks like (looking at int > > case only, same applies to UID): > > > > case int(): > > if value < 0: > > try: > > self._fp.write(struct.pack('>Bq', 0x13, value)) > > except struct.error: > > raise OverflowError(value) from None > > elif value < 1 << 8: > > self._fp.write(struct.pack('>BB', 0x10, value)) > > ... > > elif value < 1 << 64: > > self._fp.write(b'\x14' + value.to_bytes(16, 'big', > signed=True)) > > else: > > raise OverflowError(value) > > > > I was more thinking it would read/look something like: > > > > case int() if value < 0: > > try: > > self._fp.write(struct.pack('>Bq', 0x13, value)) > > except struct.error: > > raise OverflowError(value) from None > > case int() if value < 1 << 8: > > self._fp.write(struct.pack('>BB', 0x10, value)) > > ... > > case int() if value < 1 << 64: > > self._fp.write(b'\x14' + value.to_bytes(16, 'big', > signed=True)) > > case int(): > > raise OverflowError(value) > > > > Which I think works as expected under the current PEP622? > > That would work, but would be slower for the reference implementation > due to the repeated `isinstance(value, int)` checks. >
The PEP allows the compiler to generate optimized code that only checks once. > I think the repeated `int()` cases do not help readability. > Which form do you think is more readable? > I find Henk-Jaap's version better, because the case blocks show the structure of the code better. -- --Guido van Rossum (python.org/~guido) *Pronouns: he/him **(why is my pronoun here?)* <http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/>
_______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-le...@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/JNL6IRFMZU4H5IP3CKXCJ2JHROUENM2K/ Code of Conduct: http://python.org/psf/codeofconduct/