New submission from Pablo Galindo Salgado <pablog...@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 <rep...@bugs.python.org> <https://bugs.python.org/issue41746> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com