Skip to content
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

misc: add a ScopedDict util, similar to LLVM's ScopedHashTable #3355

Merged
merged 3 commits into from
Oct 30, 2024

Conversation

superlopuh
Copy link
Member

No description provided.

@superlopuh superlopuh added the misc Miscellaneous label Oct 29, 2024
@superlopuh superlopuh self-assigned this Oct 29, 2024
Copy link

codecov bot commented Oct 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (main@9003858). Learn more about missing BASE report.
Report is 8 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3355   +/-   ##
=======================================
  Coverage        ?   90.10%           
=======================================
  Files           ?      449           
  Lines           ?    56599           
  Branches        ?     5429           
=======================================
  Hits            ?    51001           
  Misses          ?     4164           
  Partials        ?     1434           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@math-fehr math-fehr left a comment

Choose a reason for hiding this comment

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

👍


from typing import Generic, TypeVar

_Key = TypeVar("_Key")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be hashable or something? I'm not sure why pyright doesn't complain here

Copy link
Member Author

Choose a reason for hiding this comment

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

Hashable isn't a real type, AFAIK, and the dict generic type has the same TypeVar definition

if local is not None:
return local
if self.parent is None:
raise KeyError()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this raise a better error message?

assigned to.
"""
if key in self._local_scope:
raise ValueError(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be a KeyError?

Copy link
Member Author

Choose a reason for hiding this comment

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

I considered it, but I have a feeling that this is not the intended purpose of KeyError, which to me signals that something does not exist for a given key, whereas this error is raised when something does already exist. In either case, I'm not sure what the user can do to recover.

@superlopuh superlopuh merged commit e6c7282 into main Oct 30, 2024
13 checks passed
@superlopuh superlopuh deleted the sasha/misc/scoped-dict branch October 30, 2024 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
misc Miscellaneous
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants