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.1

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.1
File Size Uploaded
cobble-0.1.1.tar.gz 11.7 kB Details

Release files / cobble-0.1.1.tar.gz

Download URL cobble-0.1.1.tar.gz
Size 11.7 kB
Tags Source
SHA-256 checksum
How to use checksums
e78126f709a065d4b0eb4b0a009fde520475e268d9b52b1a8b3f9dbf5c2410a1
BLAKE2b-256 checksum
How to use checksums
d838cffdf0d9b651bde6ce7c835a5fca3878343cbfae9c6406959e4ba1a3c4d6
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

0.1.2

1 release file

This release

0.1.1 This release

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