Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix/assert to typeerror#3309

Closed
NEFORCEO wants to merge 6 commits into
Kludex:mainfrom
NEFORCEO:fix/assert-to-typeerror
Closed

Fix/assert to typeerror#3309
NEFORCEO wants to merge 6 commits into
Kludex:mainfrom
NEFORCEO:fix/assert-to-typeerror

Conversation

@NEFORCEO

@NEFORCEO NEFORCEO commented May 31, 2026

Copy link
Copy Markdown

Summary

Replace assert statements with explicit TypeError raises in @requires decorator (authentication.py) and OpenAPIResponse.render (schemas.py).

assert statements are silently removed when Python runs with the -O (optimize) flag, turning helpful type mismatch messages into cryptic AttributeErrors deeper in the call stack. Using raise TypeError ensures the check always runs regardless of optimization level.

Changed files:

  • starlette/authentication.py — 3 places: websocket_wrapper, async_wrapper, sync_wrapper
  • starlette/schemas.pyOpenAPIResponse.render

Added tests:

  • tests/test_authentication.py — 3 new tests verifying TypeError is raised when sync/async request wrapper and websocket wrapper receive wrong argument types
  • tests/test_schemas.py — 1 new test verifying TypeError is raised when OpenAPIResponse receives a non-dict

Checklist

  • I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 4 files

Re-trigger cubic

@KeeganOP

Copy link
Copy Markdown
Contributor

related to: #3298 (comment)

@NEFORCEO

Copy link
Copy Markdown
Author

related to: #3298 (comment)

Done. I've changed it to raise TypeError as suggested and added the tests. Please take another look when you have a chance. Thanks!

@Kludex

Kludex commented Jun 10, 2026

Copy link
Copy Markdown
Owner

I'd actually prefer to not have this kind of plumbing for the time being.

Thanks for the PR.

@Kludex Kludex closed this Jun 10, 2026
@NEFORCEO NEFORCEO deleted the fix/assert-to-typeerror branch June 15, 2026 14:53
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.

3 participants