Skip to main content

Scala-like CaseClasses for Python

Project description

Build Status

Zero-dependency scala-like case classes for Python 2 + 3.

Features

  • Simple usage: Just inherit from case_class.CaseClass

  • Simple Installation: Zero dependencies

  • plays well with inheritance
    • CaseClass usable as a Mix-In

    • Case-to-case inheritance forbidden by default
      • use AbstractCaseClass to allow only subclasses to be instantiated

      • use InheritableCaseClass to override allow both super and subclasses to be instantiated.

  • equality based on arguments
    • calls constructor only once per combination of arguments

    • works with == operator and is (referential equality) operator.

  • automatic repr() function

  • works in both Python 2 and Python 3!

Install

This package is published on the Python Package Index Installation can be done simply via pip:

pip install case_class

Alternatively, clone this repository and run setup.py:

git clone https://github.com/tkw1536/PythonCaseClass
python setup.py install

Examples

# Import the CaseClass module
from case_class import CaseClass

# Create a symbol case class
class Symbol(CaseClass):
    def __init__(self, name):
        self.name = name

# Create an instance
x = Symbol("x")
print(x)  # Symbol('x')

# And create another one
also_x = Symbol('x')
print(x == also_x)  # equality via operator
print(x is also_x)  # referential equality

Another example can be found in example.py.

License + Acknowledgements

This module and associated documentation is Copyright (c) Tom Wiesing 2016 and licensed under the MIT license, see license for details. Small parts of the code are adapted from the six module, which is Copyright (c) 2010-2015 Benjamin Peterson.

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

case_class-0.0.3.tar.gz (8.0 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

case_class-0.0.3.macosx-10.11-x86_64.tar.gz (13.0 kB view details)

Uploaded Source

case_class-0.0.3-py2.7.egg (15.7 kB view details)

Uploaded Egg

File details

Details for the file case_class-0.0.3.tar.gz.

File metadata

  • Download URL: case_class-0.0.3.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for case_class-0.0.3.tar.gz
Algorithm Hash digest
SHA256 b2c191dd8e44603386a4a8ef82e80687a7fd8c980c8c6288671bd67ad1e64c96
MD5 6f504544cc69d3931789bba3ac096dd1
BLAKE2b-256 8f7b960f00b3242b02284d00ba7f55f91f3239ad87557501bcb571d4f6dada5e

See more details on using hashes here.

File details

Details for the file case_class-0.0.3.macosx-10.11-x86_64.tar.gz.

File metadata

File hashes

Hashes for case_class-0.0.3.macosx-10.11-x86_64.tar.gz
Algorithm Hash digest
SHA256 53070a257692fb9054938705a530e8326ce20f2c8e9b8526c61117a399bfa077
MD5 5c4ddffc9e5e8488d02ee35ec982d344
BLAKE2b-256 e766c7439c5aa7f187ac0cc48eab19340b92a00465b15879fc2db269e009e86f

See more details on using hashes here.

File details

Details for the file case_class-0.0.3-py2.7.egg.

File metadata

  • Download URL: case_class-0.0.3-py2.7.egg
  • Upload date:
  • Size: 15.7 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for case_class-0.0.3-py2.7.egg
Algorithm Hash digest
SHA256 368db80f0742ce121b0646c3892dc2f953ac9f7cab3eb8637f60ebd7bbfe15e2
MD5 dbf52ea155f839f54cb4eb1038657918
BLAKE2b-256 b91d45970ff5ef60919e20f46ffb427102770db66bb37550014a0449e80e1447

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