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

DM-37339: Fix typing on Config class #805

Merged
merged 3 commits into from Mar 24, 2023
Merged

DM-37339: Fix typing on Config class #805

merged 3 commits into from Mar 24, 2023

Conversation

timj
Copy link
Member

@timj timj commented Mar 21, 2023

Checklist

  • ran Jenkins
  • added a release note for user-visible changes to doc/changes

@timj timj force-pushed the tickets/DM-37339 branch 2 times, most recently from d1a9e37 to a039386 Compare March 21, 2023 19:23
@codecov
Copy link

codecov bot commented Mar 21, 2023

Codecov Report

Patch coverage: 95.08% and project coverage change: -0.01 ⚠️

Comparison is base (d37f7f1) 85.61% compared to head (1365f07) 85.61%.

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     
Impacted Files Coverage Δ
python/lsst/daf/butler/core/config.py 91.20% <94.54%> (-0.17%) ⬇️
python/lsst/daf/butler/_butlerConfig.py 100.00% <100.00%> (ø)
python/lsst/daf/butler/cli/utils.py 93.53% <100.00%> (+0.01%) ⬆️
python/lsst/daf/butler/core/dimensions/_config.py 84.21% <100.00%> (+0.21%) ⬆️

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.
📢 Do you have feedback about the report comment? Let us know in this issue.

# Remote resource check might be expensive
if specific.exists():
found = specific
# TODO: do we need `break` here?
Copy link
Contributor

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?

Copy link
Member Author

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...

Copy link
Contributor

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.

@andy-slac andy-slac marked this pull request as ready for review March 24, 2023 04:30
Copy link
Member Author

@timj timj left a 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?
Copy link
Member Author

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.")
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'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]
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 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?)

Copy link
Contributor

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)]
Copy link
Member Author

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.

Copy link
Contributor

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.

Copy link
Member Author

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):
Copy link
Member Author

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.

Copy link
Contributor

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.

@andy-slac andy-slac self-assigned this Mar 24, 2023
@andy-slac andy-slac merged commit f43a511 into main Mar 24, 2023
12 of 13 checks passed
@andy-slac andy-slac deleted the tickets/DM-37339 branch March 24, 2023 19:56
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.

None yet

2 participants