Skip to content

Use try:except KeyError: instead of checking-and-returning#156

Open
akx wants to merge 1 commit into
MrBin99:masterfrom
akx:keyerror
Open

Use try:except KeyError: instead of checking-and-returning#156
akx wants to merge 1 commit into
MrBin99:masterfrom
akx:keyerror

Conversation

@akx

@akx akx commented Mar 31, 2025

Copy link
Copy Markdown
Contributor

This will avoid an extra dict lookup in the "misconfigured" case; try: except: is zero-cost in Python 3.11+.

These are both pretty hot paths, so a small optimization goes a long way.

@MrBin99

MrBin99 commented May 9, 2025

Copy link
Copy Markdown
Owner

Yeah I see that but we support older versions of Python and I don't want to add costs of exceptions for people using older versions of Python. I don't know if for older versions the cost will be huge or not to have exceptions.

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