I was just working on that, although I prefer staticmethod: def allstatic(cls): for key, value in cls.__dict__.items(): if not key.startswith('__'): setattr(cls, key, staticmethod(value)) return cls @allstatic class C: def foo(a, b): print(f'{a}, {b}') C.foo('hello', 'world') C().foo('world', 'hello') It could be improved depending on the use case, for example checking for methods. Eric On 10/6/2020 10:42 AM, Guido van Rossum wrote:
I think the OP would be happy with a decorator they can just copy-paste. All it needs to do is go over the class dict and apply @classmethod to every “normal” function. Probably skip under names.
On Tue, Oct 6, 2020 at 06:46 Ricky Teachey
mailto:ricky@teachey.org> wrote: cf. this relatively recent conversation on the same topic-- worth reading in entirety:
https://mail.python.org/archives/list/python-ideas@python.org/thread/TAVHEKD...
As I said in that conversation, in the past I have wanted to have module-like namespaces inside of modules because sometimes it makes organizational sense to not create a separate, very short, module file.
Summary of how that thread turned out:
There seemed to be agreement among most of the conversation participants that this would be a useful idea, and a few different syntax ideas were batted about (a decorator, totally new syntax). A few people have experimented with various ways of doing this using current python but all of the ideas anyone has come up with so far would require some kind of change to the core language to make them work. The conversation didn't go any further than that (to my knowledge).
--- Ricky.
"I've never met a Kentucky man who wasn't either thinking about going home or actually going home." - Happy Chandler _______________________________________________ Python-ideas mailing list -- python-ideas@python.org mailto:python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org mailto:python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/QRZXD7... Code of Conduct: http://python.org/psf/codeofconduct/
-- --Guido (mobile)
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/HP6YM7... Code of Conduct: http://python.org/psf/codeofconduct/