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

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for wr-attrs-0.1.0.tar.gz
Algorithm Hash digest
SHA256 06669477bc1a3876c26fdcea006fd105873107c5ba26f575fe92327d8aaf1259
MD5 b923e6775f5a935f749e864697b0e8bb
BLAKE2b-256 7c1b44840a0853d5b875c27e65f8e35182ef86fc02f1defe5ec0fa8fdf04162c

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