Skip to main content

This is a backport of PEP487’s simpler customisation of class creation by Martin Teichmann <https://www.python.org/dev/peps/pep-0487/> for Python versions before 3.6.

PEP487 is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Subclass init

>>> from pep487 import PEP487Object
>>> class FooBase(PEP487Object):
...     foos = set()
...
...     def __init_subclass__(cls, **kwargs):
...         cls.foos.add(cls.__name__)

Using PEP487Object as base class all subclasses of FooBase will add their name to the common class variable ‘foos’.

>>> class Foo1(FooBase):
...     pass
>>> class Foo2(FooBase):
...     pass

Hence:

>>> FooBase.foos
{'Foo1', 'Foo2'}

Property names and owner

If a class object has a method __set_name__ upon declaration of an PEP487Object class, it will be called:

>>> class NamedProperty:
...     def __set_name__(self, owner, name):
...         self.context = owner
...         self.name = name
>>> class Bar(PEP487Object):
...     foo = NamedProperty()
...     bar = NamedProperty()

Consequently:

>>> Bar.foo.name is 'foo' and Bar.foo.context is Bar
True
>>> Bar.bar.name is 'bar' and Bar.bar.context is Bar
True

Abstract base classes

Since PEP487Object has a custom metaclass, it is incompatible to abc.ABC. Therefore pep487 contains patched versions of ABC and ABCMeta.

Metadata

Release files for pep487 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pep487 1.0.1
File Size Uploaded Provenance Actions
pep487-1.0.1.tar.gz 4.0 kB Without provenance Details for pep487-1.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pep487 1.0.1
File Interpreter ABI Platform Actions
pep487-1.0.1-py2.py3-none-any.whl Python 2, Python 3 none any Details for pep487-1.0.1-py2.py3-none-any.whl

Total release size: 9.5 kB

Release files / pep487-1.0.1.tar.gz

Download URL pep487-1.0.1.tar.gz
Size 4.0 kB
Tags Source
SHA-256 checksum
How to use checksums
ccca1d5b70fce64a1d52bdc3a873b47d7d67fe5b2fbf8c303f102c83f3458bfd
BLAKE2b-256 checksum
How to use checksums
44582ef69797a40ea69c0d204d5d03bb8a1cb1ea278c510b52deb01e48d07231
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / pep487-1.0.1-py2.py3-none-any.whl

Download URL pep487-1.0.1-py2.py3-none-any.whl
Size 5.5 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
8d6545f261df40becc95cceeb2cd75fc736e04731da48eb54e01e7e227060b39
BLAKE2b-256 checksum
How to use checksums
594e70a2b16a5cb39f690c6708c9db4ff003ce0c05aed12e95a7e3705df8b4eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for pep487 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page