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
DM-37339: Fix typing on Config class #805
Conversation
d1a9e37
to
a039386
Compare
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #805 +/- ##
==========================================
- Coverage 85.61% 85.61% -0.01%
==========================================
Files 266 266
Lines 35309 35314 +5
Branches 7430 7433 +3
==========================================
+ Hits 30230 30234 +4
Misses 3749 3749
- Partials 1330 1331 +1
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report in Codecov by Sentry. |
6e71cc0
to
491eb2e
Compare
# Remote resource check might be expensive | ||
if specific.exists(): | ||
found = specific | ||
# TODO: do we need `break` 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.
@timj, I think that we might want a break
here, don't we?
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.
Yes, looks like it should break out the loop once it has found something in the search path...
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.
OK, I'll add a break
and re-run Jenkins.
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.
Thanks. I can't approve it because I made the PR...
# Remote resource check might be expensive | ||
if specific.exists(): | ||
found = specific | ||
# TODO: do we need `break` 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.
Yes, looks like it should break out the loop once it has found something in the search path...
key, | ||
] | ||
# Do not try to guess. | ||
raise TypeError(f"Provided key [{key}] neither str nor iterable.") |
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'm assuming this is okay. mypy didn't like the fallback code and so it was easier for me to change it to a raise. If jenkins passes it's likely okay.
elif isinstance(key, Iterable): | ||
return list(key) | ||
return [k for k in 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.
I was unsure about this one as well. It may be that it can go back to being list(key)
(which I assume is more efficient?)
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.
list
is likely more efficient, and it should work OK, I'll put it back.
keys = [ | ||
name, | ||
] | ||
keys = [cast(str, name)] |
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.
This is probably the right thing to do but in theory name
could be a tuple -- the trick is that if in
works directly there is no reason to try anything clever.
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.
But self._data
keys are strings, right? Or at least this is how it is annotated.
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.
Okay. Yes, name
is anything but in this case we are looking in the internal dict and so yes it's only going to work if it's a string.
@@ -623,8 +621,9 @@ def __getitem__(self, name): | |||
# all further cleverness. | |||
found_directly = False | |||
try: | |||
data = self._data[name] | |||
found_directly = True | |||
if isinstance(name, str): |
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.
It does seem painful to have to do an isinstance
check even though the dict lookup would fail if the item wasn't a string but that's the price we pay for mypy. Especially when this short circuit was there as an optimization to let the fast thing be fast.
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.
Well, it is still an optimization, but for non-string case. I think checking the type first should be as quick or quicker than checking the non-string key in a dict.
e6ffff0
to
1365f07
Compare
Checklist
doc/changes