Remove some unnecessary uses of regular expressions (#101182)
This commit is contained in:
parent
09ba34fb3a
commit
5551a345ea
6 changed files with 6 additions and 16 deletions
|
@ -2,7 +2,6 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import re
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
|
@ -160,7 +159,7 @@ class IFTTTAlarmPanel(AlarmControlPanelEntity):
|
|||
"""Return one or more digits/characters."""
|
||||
if self._code is None:
|
||||
return None
|
||||
if isinstance(self._code, str) and re.search("^\\d+$", self._code):
|
||||
if isinstance(self._code, str) and self._code.isdigit():
|
||||
return CodeFormat.NUMBER
|
||||
return CodeFormat.TEXT
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ from __future__ import annotations
|
|||
|
||||
import datetime
|
||||
import logging
|
||||
import re
|
||||
from typing import Any
|
||||
|
||||
import voluptuous as vol
|
||||
|
@ -280,7 +279,7 @@ class ManualAlarm(alarm.AlarmControlPanelEntity, RestoreEntity):
|
|||
"""Return one or more digits/characters."""
|
||||
if self._code is None:
|
||||
return None
|
||||
if isinstance(self._code, str) and re.search("^\\d+$", self._code):
|
||||
if isinstance(self._code, str) and self._code.isdigit():
|
||||
return alarm.CodeFormat.NUMBER
|
||||
return alarm.CodeFormat.TEXT
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ from __future__ import annotations
|
|||
|
||||
import datetime
|
||||
import logging
|
||||
import re
|
||||
from typing import Any
|
||||
|
||||
import voluptuous as vol
|
||||
|
@ -347,7 +346,7 @@ class ManualMQTTAlarm(alarm.AlarmControlPanelEntity):
|
|||
"""Return one or more digits/characters."""
|
||||
if self._code is None:
|
||||
return None
|
||||
if isinstance(self._code, str) and re.search("^\\d+$", self._code):
|
||||
if isinstance(self._code, str) and self._code.isdigit():
|
||||
return alarm.CodeFormat.NUMBER
|
||||
return alarm.CodeFormat.TEXT
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ from __future__ import annotations
|
|||
|
||||
import functools
|
||||
import logging
|
||||
import re
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
|
@ -178,9 +177,7 @@ class MqttAlarm(MqttEntity, alarm.AlarmControlPanelEntity):
|
|||
|
||||
if (code := self._config.get(CONF_CODE)) is None:
|
||||
self._attr_code_format = None
|
||||
elif code == REMOTE_CODE or (
|
||||
isinstance(code, str) and re.search("^\\d+$", code)
|
||||
):
|
||||
elif code == REMOTE_CODE or (isinstance(code, str) and code.isdigit()):
|
||||
self._attr_code_format = alarm.CodeFormat.NUMBER
|
||||
else:
|
||||
self._attr_code_format = alarm.CodeFormat.TEXT
|
||||
|
|
|
@ -203,12 +203,9 @@ def boolean(value: Any) -> bool:
|
|||
raise vol.Invalid(f"invalid boolean value {value}")
|
||||
|
||||
|
||||
_WS = re.compile("\\s*")
|
||||
|
||||
|
||||
def whitespace(value: Any) -> str:
|
||||
"""Validate result contains only whitespace."""
|
||||
if isinstance(value, str) and _WS.fullmatch(value):
|
||||
if isinstance(value, str) and (value == "" or value.isspace()):
|
||||
return value
|
||||
|
||||
raise vol.Invalid(f"contains non-whitespace: {value}")
|
||||
|
|
|
@ -173,8 +173,7 @@ async def main():
|
|||
)
|
||||
return
|
||||
|
||||
pyfile = re.compile(r".+\.py$")
|
||||
pyfiles = [file for file in files if pyfile.match(file)]
|
||||
pyfiles = [file for file in files if file.endswith(".py")]
|
||||
|
||||
print("=============================")
|
||||
printc("bold", "CHANGED FILES:\n", "\n ".join(pyfiles))
|
||||
|
|
Loading…
Add table
Reference in a new issue