Skip to content

Fix walrus operator in assert statement, leading to problems with optimized code - #407

Merged
eigenvivek merged 2 commits into
eigenvivek:mainfrom
henrykrumb:fix-walrus-assertion
Oct 12, 2026
Merged

eigenvivek merged 2 commits into
eigenvivek:mainfrom
henrykrumb:fix-walrus-assertion

Conversation

@henrykrumb

Copy link
Copy Markdown
Contributor

Using the optimization flag -O with the Python interpreter eliminates assert statements. Thus, asserts should have no side-effects.

This small PR moves the inline assignment operator (walrus) out of an assert-statement to make it free of side-effects, so that it can be run in deployments where the -O flag is used.

Change is applied both in the original notebook and exported python module code.

@eigenvivek

Copy link
Copy Markdown
Owner

hi henry, thanks for the PR! never knew about the -O flag.

I think you just need to run nbdev_clean; nbdev_export and then the tests should pass

apologies for the nbdev framework, I though it was a great idea a few years ago but now i realize how challenging it makes PRs

henrykrumb and others added 2 commits October 12, 2026 11:07
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@eigenvivek
eigenvivek force-pushed the fix-walrus-assertion branch from 2e402a4 to c001031 Compare October 12, 2026 15:15
@eigenvivek
eigenvivek merged commit cb6c225 into eigenvivek:main Oct 12, 2026
2 checks passed
eigenvivek pushed a commit that referenced this pull request Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants