Meta Class Maybe?
So I am stuck on a problem. I have a class which I want to use to create another class without having to go through the boiler plate of subclassing. Specifically because the subclass needs to have certain class attributes and I would like to control how those are passed to provide defaults and such. What I have working right now is class Foo(): @classmethod def method_a(cls): print(cls.name) Bar = type('Bar', (Foo,), {'name': 'test1'}) Bar.method_a() This is sort of fine but the user needs to know how to call type and include all the base classes etc. I could just wrap the type call in a function like below def BarMaker(name): return type('Bar', (Foo,), {'name': name}) But then if the user needs to actually subclass Foo, to add additional methods that is more difficult. Of course those methods could be added as part of the third argument to types but that just doesn't feel very Python. This is all complicated by the fact that I am trying to avoid actually instancating any of these classes because their purpose is to be passed off to another framework to be executed. In real life most of the classes would fail to instantiate because they are relying on pieces of the framework that won't be up and running when this setup is happening. The solution I am hoping for is something like Foo(name, **kwds) -> Returns new class type of name For example test = Foo('test') So that then optionally a user could do class UserClass(Foo): def new_method(): pass bar = UserClass('Bar') Or something similar. Since I have a working example with type I feel like there should be a way to do this with the normal class structure but I am at a loss for how I have messed with the __new__ and __prepare__ methods and I can't seem to make anything work and the examples of meta classes don't clearly show how to convert my type example to a class structure. Is what I want to do possible? Chris -- https://mail.python.org/mailman/listinfo/python-list
Re: ANN: A new version (0.5.1) of python-gnupg has been released.
On 2023-07-22 at 11:04:35 +, Vinay Sajip via Python-list wrote: > What Changed? > = What changed, indeed. Maybe I'm old, and curmudgeonly, but it would be nice if the body of these annoucement emails (not just this one) contained the name of the program and a one-line summary of what the program does, preferably right at the top. (Admittedly, in this case, once I found the name of the program in the subject and the footnotes, I was able to figure out what it does. Not all software is named that usefully.) -- https://mail.python.org/mailman/listinfo/python-list
[Python-announce] ANN: A new version (0.5.1) of python-gnupg has been released.
What Changed? = This is an enhancement and bug-fix release, and all users are encouraged to upgrade. Brief summary: * Added TRUST_EXPIRED to trust_keys. * Fix #206: Remove deprecated --always-trust in favour of --trust-model always * Fix #208: Add status_detail attribute to result objects which is populated when the status is 'invalid recipient' (encryption/decryption) or 'invalid signer' (signing). This attribute will be set when the result object's status attribute is set to 'invalid recipient' and will contain more information about the failure in the form of reason:ident where reason is a text description of the reason, and ident identifies the recipient key. * Add scan_keys_mem() function to scan keys in a string. * Fix #214: Handle multiple signatures when one of them is invalid or unverified. * A problems attribute was added which holds problems reported by gpg during verification. This is a list of dictionaries, one for each reported problem. Each dictionary will have status and keyid keys indicating the problem and the corresponding key; other information in the dictionaries will be error specific. * Fix #217: Use machine-readable interface to query the gpg version. * Added the ability to export keys to a file. This release [2] has been signed with my code signing key: Vinay Sajip (CODE SIGNING KEY) Fingerprint: CA74 9061 914E AC13 8E66 EADB 9147 B477 339A 9B86 Recent changes to PyPI don't show the GPG signature with the download links. An alternative download source where the signatures are available is at [4]. The source code repository is at [1]. Documentation is available at [5]. As always, your feedback is most welcome (especially bug reports [3], patches and suggestions for improvement, or any other points via this group). Enjoy! Cheers Vinay Sajip [1] https://github.com/vsajip/python-gnupg [2] https://pypi.org/project/python-gnupg/0.5.1 [3] https://github.com/vsajip/python-gnupg/issues [4] https://github.com/vsajip/python-gnupg/releases/ [5] https://docs.red-dove.com/python-gnupg/ ___ Python-announce-list mailing list -- python-announce-list@python.org To unsubscribe send an email to python-announce-list-le...@python.org https://mail.python.org/mailman3/lists/python-announce-list.python.org/ Member address: arch...@mail-archive.com
ANN: A new version (0.5.1) of python-gnupg has been released.
What Changed? = This is an enhancement and bug-fix release, and all users are encouraged to upgrade. Brief summary: * Added TRUST_EXPIRED to trust_keys. * Fix #206: Remove deprecated --always-trust in favour of --trust-model always * Fix #208: Add status_detail attribute to result objects which is populated when the status is 'invalid recipient' (encryption/decryption) or 'invalid signer' (signing). This attribute will be set when the result object's status attribute is set to 'invalid recipient' and will contain more information about the failure in the form of reason:ident where reason is a text description of the reason, and ident identifies the recipient key. * Add scan_keys_mem() function to scan keys in a string. * Fix #214: Handle multiple signatures when one of them is invalid or unverified. * A problems attribute was added which holds problems reported by gpg during verification. This is a list of dictionaries, one for each reported problem. Each dictionary will have status and keyid keys indicating the problem and the corresponding key; other information in the dictionaries will be error specific. * Fix #217: Use machine-readable interface to query the gpg version. * Added the ability to export keys to a file. This release [2] has been signed with my code signing key: Vinay Sajip (CODE SIGNING KEY) Fingerprint: CA74 9061 914E AC13 8E66 EADB 9147 B477 339A 9B86 Recent changes to PyPI don't show the GPG signature with the download links. An alternative download source where the signatures are available is at [4]. The source code repository is at [1]. Documentation is available at [5]. As always, your feedback is most welcome (especially bug reports [3], patches and suggestions for improvement, or any other points via this group). Enjoy! Cheers Vinay Sajip [1] https://github.com/vsajip/python-gnupg [2] https://pypi.org/project/python-gnupg/0.5.1 [3] https://github.com/vsajip/python-gnupg/issues [4] https://github.com/vsajip/python-gnupg/releases/ [5] https://docs.red-dove.com/python-gnupg/ -- https://mail.python.org/mailman/listinfo/python-list