diff options
author | 2023-11-17 18:35:44 +0100 | |
---|---|---|
committer | 2023-11-29 09:21:51 -0500 | |
commit | 1f61fca68fb29e7e9e25e794386c1a7e54ab45ad (patch) | |
tree | abfe92dfe6aff58ed735e4693d8cc0173e0854cf | |
parent | grc/core/FlowGraph: pythonify old strings, lists (diff) | |
download | gnuradio-1f61fca68fb29e7e9e25e794386c1a7e54ab45ad.tar.xz gnuradio-1f61fca68fb29e7e9e25e794386c1a7e54ab45ad.zip |
grc: Extend ID blacklist by Python keywords
Signed-off-by: Marcus Müller <mmueller@gnuradio.org>
(cherry picked from commit 60ff0c99eba0f0728851d5f338329a8a53e2de05)
Signed-off-by: Jeff Long <willcode4@gmail.com>
-rw-r--r-- | grc/core/params/dtypes.py | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/grc/core/params/dtypes.py b/grc/core/params/dtypes.py index 889c7b523..097eee35f 100644 --- a/grc/core/params/dtypes.py +++ b/grc/core/params/dtypes.py @@ -15,11 +15,15 @@ from .. import Constants # Blacklist certain ids, its not complete, but should help -ID_BLACKLIST = ['self', 'gnuradio'] + dir(builtins) +ID_BLACKLIST = {'self', 'gnuradio'} | set(dir(builtins)) | set(keyword.kwlist) +# Python >= 3.10 has soft keywords in a list, i.e. words that are reserved in +# specific contexts, e.g. `match` isn't generally a keyword, but in `case` it is. +ID_BLACKLIST |= set(getattr(keyword, 'softkwlist', set())) + try: from gnuradio import gr - ID_BLACKLIST.extend(attr for attr in dir( - gr.top_block()) if not attr.startswith('_')) + ID_BLACKLIST |= {attr for attr in dir( + gr.top_block()) if not attr.startswith('_')} except (ImportError, AttributeError): pass @@ -50,8 +54,8 @@ def validate_block_id(param, black_listed_ids: List[str]) -> None: if not re.match(r'^[a-z|A-Z]\w*$', value): raise ValidateError('ID "{}" must begin with a letter and may contain letters, numbers, ' 'and underscores.'.format(value)) - if value in (black_listed_ids + ID_BLACKLIST) and \ - not getattr(param.parent_block, 'exempt_from_id_validation', False): + if (value in ID_BLACKLIST or value in black_listed_ids) \ + and not getattr(param.parent_block, 'exempt_from_id_validation', False): # Grant blacklist exemption to epy blocks and modules raise ValidateError('ID "{}" is blacklisted.'.format(value)) block_names = [ |