Skip to content

Conversation

@omad
Copy link
Member

@omad omad commented May 7, 2025

Since Python 3.8 there's functools.cached_property, which works the same way, but also passes type information through.

  • Tests passed
  • Fully documented, including docs/about/whats_new.rst for all changes

📚 Documentation preview 📚: https://opendatacube--1866.org.readthedocs.build/en/1866/

@omad omad force-pushed the replace-cached-prop branch from d00babb to ae01dd4 Compare May 7, 2025 01:51
@codecov
Copy link

codecov bot commented May 7, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.97%. Comparing base (082f10b) to head (1c20961).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1866      +/-   ##
===========================================
- Coverage    86.00%   85.97%   -0.03%     
===========================================
  Files          147      147              
  Lines        16049    16052       +3     
===========================================
- Hits         13803    13801       -2     
- Misses        2246     2251       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@omad
Copy link
Member Author

omad commented May 7, 2025

Oh dear. This works much better than I realised. It exposes more type errors! 😮‍💨

Going to have to come back to it.

@omad omad force-pushed the replace-cached-prop branch from ae01dd4 to 0811c73 Compare May 7, 2025 02:14
Copy link
Contributor

Choose a reason for hiding this comment

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

There's something funky going on with types for SQLAlchemy (but the code itself is fine), so these 3 errors can be ignored for now:

datacube/drivers/postgis/_fields.py:83: error: "FromClause" has no attribute "dataset_ref"  [attr-defined]
datacube/drivers/postgis/_fields.py:84: error: "FromClause" has no attribute "search_key"  [attr-defined]
datacube/drivers/postgis/_fields.py:101: error: "FromClause" has no attribute "search_val"  [attr-defined]

It's confusing to get these errors when making changes though, so it should be fixed, but I haven't had time to dig into that yet.

Reading the other error messages I'd say those look like real errors.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, agreed.

@omad omad force-pushed the replace-cached-prop branch 2 times, most recently from 6a9507a to 24e9669 Compare May 7, 2025 07:39
from collections import OrderedDict
from collections.abc import Iterable, Iterator, Mapping, Sequence
from datetime import datetime
from functools import cached_property
Copy link
Contributor

Choose a reason for hiding this comment

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

One of the cached properties in this file is assigned to in test_virtual.py:86, and another one in test_virtual.py:240. Is that supported by the functools cached_property, or could those two places be fixed easily so they populate the cached_property in some other way?

Copy link
Contributor

Choose a reason for hiding this comment

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

Another question is if get_by_name_unsafe.cache_clear() & friends are related to cached_property and needs to be updated in some way when replacing the implementation?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not suggesting to keep the old cached_property around, but should the release notes perhaps mention that this was removed and tell the user to use the cached_property from functools instead?

omad added 2 commits July 1, 2025 21:44
Since Python 3.8 there's functools.cached_property, which works
the same way, but also passes type information through.
The code works and is correct, typing sqlalchemy code is.. hairy
@omad omad force-pushed the replace-cached-prop branch from 24e9669 to cb002b4 Compare July 1, 2025 11:54
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.

3 participants