Skip to content

Commit

Permalink
refactor: Move regex string into a separate constant in functions.py …
Browse files Browse the repository at this point in the history
…to prevent PyCharm from showing false syntax errors.
  • Loading branch information
nfelt14 committed Feb 21, 2024
1 parent 3c72b53 commit 903c4b3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/contributing/add_new_driver.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions src/tm_devices/helpers/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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$)"
Expand Down Expand Up @@ -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)


####################################################################################################
Expand Down

0 comments on commit 903c4b3

Please sign in to comment.