-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix strptime in python_script #133159
Fix strptime in python_script #133159
Conversation
async def test_import_allow_strptime( | ||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture | ||
) -> None: | ||
"""Test that prohibited augmented assignment operations raise an error.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stale docstring
async def test_no_other_imports_allowed( | ||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture | ||
) -> None: | ||
"""Test that prohibited augmented assignment operations raise an error.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stale docstring
~~ @gjohansson-ST Looking at the linked issue, #132469, it seems this is a workaround for some change in Python 3.13. Can you please elaborate what the change in CPython is, and what the workaround does? ~~ Nevermind, I checked the change myself and updated the PR description |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @gjohansson-ST 👍
../Frenck
Co-authored-by: Erik Montnemery <erik@montnemery.com>
Proposed change
In Python 3.13,
datetime.datetime.strptime
does a local import of_strptime
.This breaks
python_script
scripts which calldatetime.datetime.strptime
because we don't allow imports.As a workaround, we add an allow-list of safe import,
_strptime
is currently the only allowed import.Type of change
Additional information
Checklist
ruff format homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
.To help with the load of incoming pull requests: