René's URL Explorer Experiment


Title: Memoize key isn't always invertible · Issue #313 · grantjenks/python-diskcache · GitHub

Open Graph Title: Memoize key isn't always invertible · Issue #313 · grantjenks/python-diskcache

X Title: Memoize key isn't always invertible · Issue #313 · grantjenks/python-diskcache

Description: Hey, really appreciate this library! I have a small feature request (and an accompanying PR), which is just to make the .__cache_key__ of a memoized function invertible (which also means making args_to_key actually produce unique keys fo...

Open Graph Description: Hey, really appreciate this library! I have a small feature request (and an accompanying PR), which is just to make the .__cache_key__ of a memoized function invertible (which also means making arg...

X Description: Hey, really appreciate this library! I have a small feature request (and an accompanying PR), which is just to make the .__cache_key__ of a memoized function invertible (which also means making arg...

Opengraph URL: https://github.com/grantjenks/python-diskcache/issues/313

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Memoize key isn't always invertible","articleBody":"Hey, really appreciate this library!\r\n\r\nI have a small feature request (and an accompanying PR), which is just to make the `.__cache_key__` of a `memoize`d function invertible (which also means making `args_to_key` actually produce unique keys for different arguments).\r\n\r\nA use case is migrating many different cached functions due to a source changes, e.g. suppose we had some caches that have been populated using:\r\n\r\n```python\r\n@cache.memoize\r\ndef foo(a: OldClass):\r\n    ...\r\n\r\n@cache.memoize\r\ndef bar(b: OldClass, c: OldClass | None = None):\r\n    ...\r\n```\r\n\r\nand want to roll out new versions of these\r\n\r\n```python\r\n@cache.memoize\r\ndef foo(anew: NewClass):\r\n    ...\r\n\r\n@cache.memoize\r\ndef bar(*, bnew: NewClass, c: NewClass | None = None):\r\n    ...\r\n```\r\n\r\nand want to update migrate all of `OldClass` arguments to some `NewClass`, as well as changing the signatures appropriately, so that we can keep our old caches, e.g. via something like\r\n\r\n```python\r\nimport diskcache as dc\r\n\r\n...\r\n\r\nfor old_key in old_cache.iterkeys():\r\n    # some random function to deal with qualname changes\r\n    new_key_base = get_new_qualname(old_key[0])\r\n    # some random function to update any values/types and the signature\r\n    new_args, new_kwargs = get_new_args_kwargs(old_key)\r\n    new_key = dc.core.args_to_key(\r\n        new_key_base, new_args, new_kwargs, typed=typed, ignore=ignore\r\n    )\r\n    new_cache.add(new_key, old_cache.get(old_key))\r\n```\r\n\r\nSince https://github.com/grantjenks/python-diskcache/issues/195 / https://github.com/grantjenks/python-diskcache/commit/d55a50ee083784afa9c85e14e41c4a2d132f3111, then the `args` and `kwargs` delimiter in `args_to_key` is no longer a special sentinel, and so `get_new_args_kwargs` needs to know the signature of whichever function it was previously caching to faithfully find out the arguments used for that key. Namely, there's signatures where we couldn't faithfully determine where the `(None,)` delimiter between `args` and `kwargs` in `args_to_key` is placed (if `typed=False`), e.g. for\r\n\r\n```python\r\n@cache.memoize\r\ndef f(*args, b=None, c=0):\r\n    ...\r\n\r\nassert f.__cache_key__(None, \"b\", c=1) == f.__cache_key__(None, b=None, c=1)\r\n```\r\n\r\nMy proposed fix (https://github.com/grantjenks/python-diskcache/pull/312) is just to change the `key` accumulation of `kwargs` to use its (key, value) pairs.\r\n\r\n","author":{"url":"https://github.com/liammcinroy","@type":"Person","name":"liammcinroy"},"datePublished":"2024-04-16T13:57:56.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/313/python-diskcache/issues/313"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:6fab94b2-2087-204a-5c51-6951c730bee6
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idC5F4:3053B5:DA3567:1236E8E:69698B1A
html-safe-nonce326e5674163a99d666d591198093a48fa6ba4e83c8bd58a7ab18e37b267e0cf6
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNUY0OjMwNTNCNTpEQTM1Njc6MTIzNkU4RTo2OTY5OEIxQSIsInZpc2l0b3JfaWQiOiIzMjE5OTYwMjQwODI3NjMyNDEwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmacbb4397771f363d3d9429064f488b6ece1f78935e8ea7ab6920da50f3c6c5b582
hovercard-subject-tagissue:2246139342
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/grantjenks/python-diskcache/313/issue_layout
twitter:imagehttps://opengraph.githubassets.com/533bfb0cee85e2ae246bb288ab6b78078901f392984d7be3eb41a343e31663b9/grantjenks/python-diskcache/issues/313
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/533bfb0cee85e2ae246bb288ab6b78078901f392984d7be3eb41a343e31663b9/grantjenks/python-diskcache/issues/313
og:image:altHey, really appreciate this library! I have a small feature request (and an accompanying PR), which is just to make the .__cache_key__ of a memoized function invertible (which also means making arg...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameliammcinroy
hostnamegithub.com
expected-hostnamegithub.com
None533e7cac596c452090972c1150d587fd0b36531b8dc4e8bbfe4ab694aca02408
turbo-cache-controlno-preview
go-importgithub.com/grantjenks/python-diskcache git https://github.com/grantjenks/python-diskcache.git
octolytics-dimension-user_id118304
octolytics-dimension-user_logingrantjenks
octolytics-dimension-repository_id51039722
octolytics-dimension-repository_nwograntjenks/python-diskcache
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id51039722
octolytics-dimension-repository_network_root_nwograntjenks/python-diskcache
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release63d27af10eea2ccab520b162530cf6c7b739e767
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/grantjenks/python-diskcache/issues/313#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgrantjenks%2Fpython-diskcache%2Fissues%2F313
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgrantjenks%2Fpython-diskcache%2Fissues%2F313
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=grantjenks%2Fpython-diskcache
Reloadhttps://github.com/grantjenks/python-diskcache/issues/313
Reloadhttps://github.com/grantjenks/python-diskcache/issues/313
Reloadhttps://github.com/grantjenks/python-diskcache/issues/313
grantjenks https://github.com/grantjenks
python-diskcachehttps://github.com/grantjenks/python-diskcache
Notifications https://github.com/login?return_to=%2Fgrantjenks%2Fpython-diskcache
Fork 155 https://github.com/login?return_to=%2Fgrantjenks%2Fpython-diskcache
Star 2.8k https://github.com/login?return_to=%2Fgrantjenks%2Fpython-diskcache
Code https://github.com/grantjenks/python-diskcache
Issues 49 https://github.com/grantjenks/python-diskcache/issues
Pull requests 17 https://github.com/grantjenks/python-diskcache/pulls
Actions https://github.com/grantjenks/python-diskcache/actions
Projects 0 https://github.com/grantjenks/python-diskcache/projects
Security Uh oh! There was an error while loading. Please reload this page. https://github.com/grantjenks/python-diskcache/security
Please reload this pagehttps://github.com/grantjenks/python-diskcache/issues/313
Insights https://github.com/grantjenks/python-diskcache/pulse
Code https://github.com/grantjenks/python-diskcache
Issues https://github.com/grantjenks/python-diskcache/issues
Pull requests https://github.com/grantjenks/python-diskcache/pulls
Actions https://github.com/grantjenks/python-diskcache/actions
Projects https://github.com/grantjenks/python-diskcache/projects
Security https://github.com/grantjenks/python-diskcache/security
Insights https://github.com/grantjenks/python-diskcache/pulse
New issuehttps://github.com/login?return_to=https://github.com/grantjenks/python-diskcache/issues/313
New issuehttps://github.com/login?return_to=https://github.com/grantjenks/python-diskcache/issues/313
Memoize key isn't always invertiblehttps://github.com/grantjenks/python-diskcache/issues/313#top
https://github.com/liammcinroy
https://github.com/liammcinroy
liammcinroyhttps://github.com/liammcinroy
on Apr 16, 2024https://github.com/grantjenks/python-diskcache/issues/313#issue-2246139342
#195https://github.com/grantjenks/python-diskcache/issues/195
d55a50ehttps://github.com/grantjenks/python-diskcache/commit/d55a50ee083784afa9c85e14e41c4a2d132f3111
#312https://github.com/grantjenks/python-diskcache/pull/312
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.