python-babel / babel

The official repository for Babel, the Python Internationalization Library
http://babel.pocoo.org/
BSD 3-Clause "New" or "Revised" License
1.34k stars 448 forks source link

Fix #774: Allow object methods to be used as extraction-keywords #1136

Open embray opened 2 months ago

embray commented 2 months ago

Proof of concept fix for #774. I did this quickly using peekable() from the more-itertools package, but if adding a new dependency just for this is (understandably) undesirable, it could be fixed just as easily with slight improvements to the generate tokens loop (in fact I had a version of that working earlier, but it gets a bit hairier with the nested case).

This would conflict with #1127, so if this is otherwise acceptable as a feature can rebase on top of that and without using more-itertools.

akx commented 1 month ago

Thank you! Yeah, this makes sense, but we definitely don't want an extra dependency :)

Maybe we can vendor (a subset of) peekable if that makes implementing this easier. Tests should also ensure multi-dotted names such as my.corporate.app.translations.execute() work :)

embray commented 1 month ago

Great, given the go-ahead I'll rework this. peekable() is nice but I don't think it's really needed either.

I like how your example pokes fun at the "Enterprise-y" nature of this ;). But I swear I had a really good use case for this and wanted to make it work.