-
Notifications
You must be signed in to change notification settings - Fork 80
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
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
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.
👍
|
||
from typing import Generic, TypeVar | ||
|
||
_Key = TypeVar("_Key") |
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.
Should this be hashable or something? I'm not sure why pyright doesn't complain here
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.
Hashable isn't a real type, AFAIK, and the dict
generic type has the same TypeVar
definition
xdsl/utils/scoped_dict.py
Outdated
if local is not None: | ||
return local | ||
if self.parent is None: | ||
raise KeyError() |
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.
Should this raise a better error message?
assigned to. | ||
""" | ||
if key in self._local_scope: | ||
raise ValueError( |
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.
Should this be a KeyError
?
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.
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.
No description provided.