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

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for wr-attrs-0.1.2.tar.gz
Algorithm Hash digest
SHA256 53cec5a732105b58667238192320f76bfa83e542a1e73e3b515340fbd9c8ec88
MD5 5ef99a34181e341106c2670c8937856b
BLAKE2b-256 40e0d901328fdfb6cae1b177174b6050c05d561a0b5d3533543fb5047f7e0102

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