Skip to main content

wr-attrs

Project description

# wr-attrs


* Attributes are descriptors for classes and values for instances

class A(AttrContainer):
p = Attr()

a = A()

assert isinstance(A.p, Attr)
assert A.p.name == 'p'
assert A.p.default is None

assert a.p is None

* Attributes can be easily initialised

a = A(p=23)

assert isinstance(A.p, Attr)
assert A.p.default is None

assert a.p == 23

* Attributes are inherited

class B(A):
q = Attr()
r = Attr()

b = B(p=23, q=42)

assert B.p is A.p

assert b.p == 23
assert b.q == 42
assert b.r is None


* Attributes are registered in a collection.

b = B(q=42)

assert len(b.attrs) == 3
assert b.attrs.names == ['p', 'q', 'r']
assert list(b.attrs.values) == [('p', None), ('q', 42), ('r', None)]

assert b.attrs.q is B.q
assert b.attrs['q'] is B.q
assert b.attrs.get('q') == 42


* Attributes can have default values set in inherited classes without overwriting
the descriptor.

class C(B):
p = 0
q = 1

c = C()

assert c.p == 0
assert c.q == 1
assert c.r is None

assert C.p is B.p
assert C.q is B.q
assert C.r is B.r

* Attributes can have custom setters.

class D(C):
s = Attr()

@s.setter
def s(self, value):
self.attrs.set('s', value * 5)

d = D(s=0)
d.s = 5
assert d.s == 25

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wr-attrs-0.1.1.tar.gz (5.4 kB view details)

Uploaded Source

File details

Details for the file wr-attrs-0.1.1.tar.gz.

File metadata

  • Download URL: wr-attrs-0.1.1.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for wr-attrs-0.1.1.tar.gz
Algorithm Hash digest
SHA256 8b48c88d6a2ec7b04ff7c23785e5ae7e98a8dd6c9bb5e452e0eb1306baa4a2ab
MD5 a5b59667c3bbfc8a7286804ee19251a1
BLAKE2b-256 270b27a48ec7b8167d968fa8d5652913e109de75ea281b908b174f933db66204

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page