You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Had a look at cylc-get-host-metrics today and noticed a warning in the IDE for the function extract_pattern. Copied below:
defextract_pattern(data_pattern, raw_string):
"""Try to return first parenthesized subgroup of a regex string search."""error_msg="No 're.search' matches for:\n %s\non the string:\n %s"% (
data_pattern.pattern, raw_string)
try:
matches=re.search(data_pattern, raw_string)
exceptre.error:
sys.stderr.write(error_msg)
ifmatches:
returnmatches.groups()
else:
raiseAttributeError(error_msg)
The issue is that if we reach except re.error, and matches is not set, the next if matches statement would raise a NameError.
However; there is no way for re.error to happen I think. Because a few lines before we have data_pattern.pattern, which means that the data_pattern is not a string, but a compiled regex pattern.
Can't tell whether we should fix and accept string, or ignore the re.error, or just declare match somewhere else... a bit confusing.
Low priority issue, probably will go away with future changes.
NA, couldn't write a unit test failing as well, because I think re.error cannot be raised 😕
Expected behavior
I guess type hints either in the comments or signature to indicate what the data_pattern type is, and simplify the code.
Screenshots
Additional context
Pull requests welcome!
This is an Open Source project - please consider contributing a bug fix
yourself (please read CONTRIBUTING.md before starting any work though).
The text was updated successfully, but these errors were encountered:
Describe the bug
Had a look at
cylc-get-host-metrics
today and noticed a warning in the IDE for the functionextract_pattern
. Copied below:The issue is that if we reach
except re.error
, andmatches
is not set, the nextif matches
statement would raise aNameError
.However; there is no way for
re.error
to happen I think. Because a few lines before we havedata_pattern.pattern
, which means that thedata_pattern
is not a string, but a compiled regex pattern.Can't tell whether we should fix and accept string, or ignore the re.error, or just declare match somewhere else... a bit confusing.
Low priority issue, probably will go away with future changes.
Release version(s) and/or repository branch(es) affected?
master
and 8.0a1Steps to reproduce the bug
NA, couldn't write a unit test failing as well, because I think
re.error
cannot be raised 😕Expected behavior
I guess type hints either in the comments or signature to indicate what the
data_pattern
type is, and simplify the code.Screenshots
Additional context
Pull requests welcome!
This is an Open Source project - please consider contributing a bug fix
yourself (please read
CONTRIBUTING.md
before starting any work though).The text was updated successfully, but these errors were encountered: