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.2.0.tar.gz (6.4 kB view details)

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for wr-attrs-0.2.0.tar.gz
Algorithm Hash digest
SHA256 4e80bdea70fb1686cda24e2022deaa9562a850c3d1e99811e14db52be9d18ac7
MD5 9041ca4c9058710511263489046d9493
BLAKE2b-256 d773acecb42ae416f3e0f8366c13c204bac57d783d575b11fabf94068662d3cf

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