[New-bugs-announce] [issue41746] Add optional type information to asdl_seq objects

Pablo Galindo Salgado report at bugs.python.org
Tue Sep 8 16:31:17 EDT 2020


New submission from Pablo Galindo Salgado <pablogsal at gmail.com>:

Casting incorrect elements pulled from asdl_seq objects has been a pain when developing the new PEG parser and is a source of spooky-bug-at-a-distance problems in which the consequences of an incorrect casting from void* are felt much later.

I propose to add a new field to asdl_seq objects, which is an enumeration of the possible types it can contain. The main ideas are:

* By default, the enumeration will have UNDEFINED type.
* We can add some extra macros mirroring asdl_seq_GET and asdl_seq_SET that will receive the expected type and in debug mode will assert that the type is correct. Something like:

expr_ty item = asdl_set_GET_TYPED(sequence, n, EXPR);

* Usage of asdl_seq_GET and asdl_seq_SET do not do extra checks.

* To set the type information, we can add a new constructor:

asdl_seq_new_typed(size, arena, TYPE);

I think this change is worth because is not very invasive (old usage remains the same), we can slowly migrate only the parts that we need/want and will add some extra debugging possibilities for cases that has been quite challenging.

----------
components: Interpreter Core
messages: 376592
nosy: gvanrossum, lys.nikolaou, pablogsal
priority: normal
severity: normal
status: open
title: Add optional type information to asdl_seq objects
versions: Python 3.10

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41746>
_______________________________________


More information about the New-bugs-announce mailing list