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-31722: Clean up utility code usage #582

Merged
merged 14 commits into from Oct 8, 2021
Merged

DM-31722: Clean up utility code usage #582

merged 14 commits into from Oct 8, 2021

Conversation

timj
Copy link
Member

@timj timj commented Oct 1, 2021

Requires lsst/utils#100

Checklist

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

@codecov
Copy link

codecov bot commented Oct 1, 2021

Codecov Report

Merging #582 (ac75d50) into master (7950aa3) will decrease coverage by 0.15%.
The diff coverage is 78.75%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #582      +/-   ##
==========================================
- Coverage   83.62%   83.47%   -0.16%     
==========================================
  Files         241      241              
  Lines       30347    30136     -211     
  Branches     4517     4497      -20     
==========================================
- Hits        25379    25156     -223     
- Misses       3781     3786       +5     
- Partials     1187     1194       +7     
Impacted Files Coverage Δ
python/lsst/daf/butler/core/serverModels.py 0.00% <0.00%> (ø)
python/lsst/daf/butler/registries/remote.py 0.00% <0.00%> (ø)
python/lsst/daf/butler/core/quantum.py 67.69% <20.00%> (-3.28%) ⬇️
...hon/lsst/daf/butler/datastores/chainedDatastore.py 86.41% <42.85%> (-1.23%) ⬇️
python/lsst/daf/butler/core/datastore.py 74.00% <50.00%> (-0.75%) ⬇️
python/lsst/daf/butler/core/dimensions/_skypix.py 89.77% <50.00%> (-4.21%) ⬇️
...hon/lsst/daf/butler/registry/dimensions/caching.py 90.90% <50.00%> (-3.44%) ⬇️
python/lsst/daf/butler/registry/_registry.py 72.31% <60.00%> (-0.68%) ⬇️
python/lsst/daf/butler/registry/_config.py 80.00% <71.42%> (-1.25%) ⬇️
python/lsst/daf/butler/core/logging.py 96.17% <77.77%> (-0.92%) ⬇️
... and 37 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7950aa3...ac75d50. Read the comment docs.

@timj timj force-pushed the tickets/DM-31722 branch 4 times, most recently from 81ae4f0 to e514ba5 Compare October 5, 2021 04:21
Copy link
Member

@TallJimbo TallJimbo left a comment

Choose a reason for hiding this comment

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

As an aside: it'd be really nice to be able to click a button on all those CodeCov annotations and say, "don't worry about coverage for this line ever again". I don't suppose you know of anything like that?

python/lsst/daf/butler/core/dimensions/_skypix.py Outdated Show resolved Hide resolved
records = [ButlerLogRecord.parse_raw(line) for line in isplit(serialized, newline) # type: ignore
if line]
# argument to isplit() [which can't have two different types
# simultaneously] so we have to duplicate some logic.
Copy link
Member

Choose a reason for hiding this comment

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

I'm curious what the mypy error was with the original code.

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 was complaining that Union[str, bytes] for the separator can't work for a str parameter that is being split because the T type can't then work out what the return type is. With the rewrite it knows that serialized is the same type as newline so can know what isplit returns. Fundamentally if a variable at any point has a Union type it can't be converted to a non-Union type without being assigned to a new variable.

Copy link
Member

Choose a reason for hiding this comment

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

Fundamentally if a variable at any point has a Union type it can't be converted to a non-Union type without being assigned to a new variable.

I've definitely seen mypy "collapse" a union down to the remaining type(s) when one of them is rejected in other contexts (e.g. if you assert x is not None, it can tell that x is T in Optional[T]). But I guess there's not much value in trying to figure out why it couldn't do that 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.

I think adding 4 asserts (two in each if branch) might do it but I'm not sure if that's much of an improvement.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed; fine as-is.

@timj
Copy link
Member Author

timj commented Oct 6, 2021

The code coverage reports only turn up for new code on this pull request. If I merge this PR and no-one else ever touches that code, codecov will never report any coverage problem. I added new code with an if clause that is not triggered by any of the tests and so that counts against this PR as being a drop in coverage. Codecov is complaining about this PR because there was a net decrease in code coverage because I added all these checks for mypy. I can ignore them and merge or I can create a few bad config files and try to create butlers from them.

@TallJimbo
Copy link
Member

I can ignore them and merge or I can create a few bad config files and try to create butlers from them.

I am all for ignoring them here. I was just hoping we could ignore them forever (e.g. keep them from coming back again if we, say, black-formatted everything), but it sounds like it doesn't matter much anyway.

@timj
Copy link
Member Author

timj commented Oct 6, 2021

If we black-formatted everything then codecov would absolutely lose its mind because of the 16% of the codebase that has no code coverage at all. We'd have to take that on the chin. I don't think it's unreasonable for codecov to warn you when you've edited a line but don't have any test code to show that the edit made a difference.

Many utility routines have been relocated to the lsst.utils package.
Remove them from daf_butler and use them.
It is not used and ButlerURI version is preferred.
os.makedirs is now safe
@timj timj force-pushed the tickets/DM-31722 branch 2 times, most recently from b69959c to b9f8c3e Compare October 7, 2021 17:16
mypy noted that doImport can return a Module and this was not
expected in many cases. mypy also requires that there is a check
on the return value from doImportType to ensure that it is
of the correct class.
Mypy does not like

  isplit(str, str | bytes)

so rearrange the logic to have distinct calls to isplit for
str and bytes.
@timj timj merged commit 27e3c37 into master Oct 8, 2021
@timj timj deleted the tickets/DM-31722 branch October 8, 2021 15:34
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