From ff456db65d626bd6b33be6fda8de8cd3b8ad40dd Mon Sep 17 00:00:00 2001 From: mohit-emerson Date: Tue, 27 Oct 2026 02:28:55 +0000 Subject: [PATCH] Skip repeated capability validation when InvalidRepeatedCapabilityError is not generated Drivers that have repeated capabilities but do not list InvalidRepeatedCapabilityError in extra_errors_used now pass repeated capability strings they cannot parse to the driver as-is, and the driver reports if they are invalid. Only a simple two-part range is expanded, and unsupported types raise TypeError. Drivers that list the error generate the same code as before. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- build/templates/_converters.py.mako | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/build/templates/_converters.py.mako b/build/templates/_converters.py.mako index 2ee4ba6630..963fabcfb1 100644 --- a/build/templates/_converters.py.mako +++ b/build/templates/_converters.py.mako @@ -5,13 +5,17 @@ ${template_parameters['encoding_tag']} config = template_parameters['metadata'].config module_name = config['module_name'] extra_errors_used = config['extra_errors_used'] + # Drivers that have repeated capabilities but do not generate InvalidRepeatedCapabilityError pass repeated capabilities they cannot parse to the driver as-is + validate_repeated_capabilities = 'InvalidRepeatedCapabilityError' in extra_errors_used or len(config['repeated_capabilities']) == 0 enums = config['enums'] %>\ import ${module_name}._visatype as _visatype % if any(helper.enum_uses_converter(enums[enum_name]) for enum_name in helper.filter_codegen_enums(enums)): import ${module_name}.enums as enums % endif +% if validate_repeated_capabilities: import ${module_name}.errors as errors +% endif import array import collections @@ -51,7 +55,11 @@ def _convert_repeated_capabilities(arg, prefix): # noqa: F811 - (slice(0, 1), '2', [4, '5-6'], '7-9', '11:14', '16, 17') --> ['0', '2', '4', '5', '6', '7', '8', '9', '11', '12', '13', '14', '16', '17'] ''' +% if validate_repeated_capabilities: raise errors.InvalidRepeatedCapabilityError('Invalid type', type(arg)) +% else: + raise TypeError('Invalid type for a repeated capability: {}'.format(type(arg))) +% endif @_convert_repeated_capabilities.register(numbers.Integral) # noqa: F811 @@ -77,9 +85,14 @@ def _(repeated_capability, prefix): # We remove any prefix and change ':' to '-' r = repeated_capability.strip().replace(prefix, '').replace(':', '-') rc = r.split('-') +% if validate_repeated_capabilities: if len(rc) > 1: if len(rc) > 2: raise errors.InvalidRepeatedCapabilityError("Multiple '-' or ':'", repeated_capability) +% else: + # Only a simple range can be expanded. Anything else, such as 'calplane::plane1/port::if1', is returned as-is + if len(rc) == 2: +% endif try: start = int(rc[0]) end = int(rc[1])