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

maint: convert to cached_property and other minor refactors #1870

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

maresb
Copy link
Contributor

@maresb maresb commented Dec 26, 2024

This is a continuation of #1760.

I have a few motivations. One is to understand why some of the version-computing logic is so complicated, and to simplify that if possible. (See for example maresb/hatch-vcs-footgun-example#3.) Also, I have fantasies about being able to close #304.

In each case, I need to understand in detail what the code is doing so that I can make modifications without causing breakage. But then I get bogged down in complexity that to me seems inessential. So as I go through this process, I try to either eliminate inessential complexity or to document why the complexity is essential.

Currently, property values are cached by-hand in a variable of the same name prefixed with an underscore. As long as this variable is only used by that property, and only with the usual caching boilerplate, this can be directly converted to @cached_property by adding the decorator and removing the cache variable and boilerplate. Sometimes the property is a mutable container like ProjectMetadata.dynamic (which is depopulated as dynamic values are computed), but this detail doesn't affect the caching logic. In other cases like CoreMetadata._readme_content_type, the variable is modified not only by the .readme_content_type property but also the .readme property. Since this PR is already getting a bit heavy I have left these cases untouched.

Along the way I've made a few other very minor refactors and added some comments.

Hopefully I made no mistakes and these changes are helpful. Thanks!

@maresb maresb force-pushed the cleanup branch 2 times, most recently from c38af0f to a134274 Compare December 26, 2024 17:46
@maresb maresb marked this pull request as draft December 26, 2024 19:44
@maresb
Copy link
Contributor Author

maresb commented Dec 26, 2024

I messed up .version due to a previously-incorrect type hint. Need to fix that, converting to draft.

@maresb maresb force-pushed the cleanup branch 7 times, most recently from 7370db0 to bbab731 Compare December 27, 2024 20:54
@maresb
Copy link
Contributor Author

maresb commented Dec 28, 2024

Hi @ofek, this is ready for review.

Urgency is low. (I just hope this can be merged before too many merge conflicts develop.)

I'm trying to refactor to take advantage of recent language features and make other things a little bit simpler to understand.

I'm very interested in feedback, especially if you spot any errors. Most commits are independent, so if there's anything you don't like I can rebase it away. Thanks a lot for your consideration, and happy holidays!!!

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.

Supporting non-root VCS ignore
1 participant