kalekundert / byoc

MIT License
0 stars 0 forks source link

Think about switching to `@cached_property`-style caching #27

Closed kalekundert closed 2 years ago

kalekundert commented 2 years ago

The library would be much simpler conceptually if it were to just calculate a value the first time it was accessed, then overwrite itself with that value. AppCLI attributes just be elaborate default values: nothing more and nothing less.

The simplicity of this mental model really appeals to me, but I'd have to modify/eliminate some existing features:

Overall, this seems like it'd actually be a pretty small change. It wouldn't simplify the code at all (even though I still think of it as a conceptual simplification), because I'd have to keep all the current code to support these more complex cases. But I also wouldn't need to rewrite much existing code. Here's some pseudo-code:

kalekundert commented 2 years ago

I ran into a problem implementing this: python doesn't let the instance dictionary shadow the descriptor if the descriptor implements __set__ or __del__. So I'd need to get rid of those methods in order for this feature to be worth it. Can I do that?

The metadata issue is the hangup. Even though it's a small feature, it's something that's squarely within appcli's purview, and there's just no way to get it right without __set__.

I saved my work-in-progress to the feat-fast-cache branch, but I'm going to abandon this feature for now.