From 903c4b3f5355e8e01a19b5f4f8a3b2ae4b5a31cc Mon Sep 17 00:00:00 2001 From: Nicholas Felt Date: Tue, 20 Feb 2024 16:10:56 -0800 Subject: [PATCH] refactor: Move regex string into a separate constant in functions.py to prevent PyCharm from showing false syntax errors. --- docs/contributing/add_new_driver.md | 2 +- src/tm_devices/helpers/functions.py | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/contributing/add_new_driver.md b/docs/contributing/add_new_driver.md index db23a446..ccc1e424 100644 --- a/docs/contributing/add_new_driver.md +++ b/docs/contributing/add_new_driver.md @@ -25,7 +25,7 @@ This guide will walk through the steps needed to add a new device driver. - See other `__init__.py` files for examples 04. Update the `SupportedModels` enum exposed in `tm_devices/helpers/__init__.py` -05. Update the `_SUPPORTED_MODEL_REGEX_MAPPING` regex constant inside +05. Update the `___SUPPORTED_MODEL_REGEX_STRING` regex constant inside `tm_devices/helpers/functions.py` to include a mapping of the new driver name (model series) to a regex string matching the appropriate model strings 06. Update the `DEVICE_DRIVER_MODEL_MAPPING` lookup inside diff --git a/src/tm_devices/helpers/functions.py b/src/tm_devices/helpers/functions.py index b96dee21..20a03395 100644 --- a/src/tm_devices/helpers/functions.py +++ b/src/tm_devices/helpers/functions.py @@ -44,9 +44,7 @@ #################################################################################################### # Private Constants #################################################################################################### -# NOTE: This regex will show as having a bunch of errors in the PyCharm IDE due to an -# open bug affecting f-strings in regex: https://youtrack.jetbrains.com/issue/PY-52140 -_SUPPORTED_MODEL_REGEX_MAPPING = re.compile( +__SUPPORTED_MODEL_REGEX_STRING = ( # AFGs rf"(?P<{SupportedModels.AFG3K.value}>^AFG3\d\d\d$)" rf"|(?P<{SupportedModels.AFG3KB.value}>^AFG3\d\d\dB$)" @@ -155,6 +153,10 @@ # SSs rf"|(?P<{SupportedModels.SS3706A.value}>^3706A$)" ) +# NOTE: This regex would show as having a bunch of errors in the PyCharm IDE due to an +# open bug affecting f-strings in regex: https://youtrack.jetbrains.com/issue/PY-52140. +# For this reason, the regex string itself is stored in a separate, private constant. +_SUPPORTED_MODEL_REGEX_MAPPING = re.compile(__SUPPORTED_MODEL_REGEX_STRING) ####################################################################################################