Skip to main content

Cobble is a Python library that allows easy creation of data objects, including implementations of common methods such as __eq__ and __repr__.

Examples

import cobble

@cobble.data
class Song(object):
    name = cobble.field()
    artist = cobble.field()
    album = cobble.field(default=None)


song = Song("MFEO", artist="Jack's Mannequin")

print(song) # Prints "Song(name='MFEO', artist="Jack's Mannequin", album=None)"
class Expression(object):
    pass

@cobble.data
class Literal(Expression):
    value = cobble.field()

@cobble.data
class Add(Expression):
    left = cobble.field()
    right = cobble.field()

class Evaluator(cobble.visitor(Expression)):
    def visit_literal(self, literal):
        return literal.value

    def visit_add(self, add):
        return self.visit(add.left) + self.visit(add.right)

Evaluator().visit(Add(Literal(2), Literal(4))) # 6
class Expression(object):
    pass

@cobble.visitable
class Literal(Expression):
    def __init__(self, value):
        self.value = value

@cobble.visitable
class Add(Expression):
    def __init__(self, left, right):
        self.left = left
        self.right = right

class Evaluator(cobble.visitor(Expression)):
    def visit_literal(self, literal):
        return literal.value

    def visit_add(self, add):
        return self.visit(add.left) + self.visit(add.right)

Evaluator().visit(Add(Literal(2), Literal(4))) # 6

License

2-Clause BSD

Metadata

Release files for cobble 0.1.2

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

Source distribution (sdist)

Source distribution for cobble 0.1.2
File Size Uploaded
cobble-0.1.2.tar.gz 11.0 kB Details

Release files / cobble-0.1.2.tar.gz

Download URL cobble-0.1.2.tar.gz
Size 11.0 kB
Tags Source
SHA-256 checksum
How to use checksums
1aee1cc095098f298cb9c87b96ef497c63e7ebe5b7b5eacf1de280b1da1c6779
BLAKE2b-256 checksum
How to use checksums
d66842b71952fb6ef916a89be460441197e8dba462f98721d8851b88dc8a375d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

0.1.4

2 release files

0.1.3

1 release file

This release

0.1.2 This release

1 release file

0.1.1

1 release file

0.1.0

1 release file

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