coleifer / micawber

a small library for extracting rich content from urls
http://micawber.readthedocs.org/
MIT License
635 stars 91 forks source link

Update the RedisCache's key_fn to actually only require one argument #108

Closed matthiask closed 1 year ago

matthiask commented 1 year ago

I'm not 100% sure what's going on here. My first hunch was that there's a difference between Python 2 and 3's handling of assigned functions, but that doesn't seem to be the case. Certainly, key_fn doesn't act as a method but as a function even though it's assigned to a class (but on the instance, not on the class itself)

I didn't add tests because right now the tests do not depend on redis and I assume that you want to keep it that way.

Thanks!

Python 3.10.6 (main, May 29 2023, 11:10:38) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> class Thing:
...     def __init__(self):
...         self.fn = lambda hello: hello
...
>>> t = Thing()
>>> t.fn("hello")
'hello'
>>>
coleifer commented 1 year ago

This must've been an older python thing, though memory fails me. I've implemented this change slightly differently, just pushing key_fn to a method: 4e1af2c4566e969a143bbc156d4e962c80318717

matthiask commented 1 year ago

Thanks!