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 and AbstractCaseClass` 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.`

    • also plays well with Multiple Inheritance * super() calls still work as expected

  • 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.4.tar.gz (7.8 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.4.macosx-10.11-x86_64.tar.gz (12.6 kB view details)

Uploaded Source

case_class-0.0.4-py3.5.egg (15.5 kB view details)

Uploaded Egg

case_class-0.0.4-py2.7.egg (15.3 kB view details)

Uploaded Egg

File details

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

File metadata

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

File hashes

Hashes for case_class-0.0.4.tar.gz
Algorithm Hash digest
SHA256 1c378088b915b9d9c55525e68238e56c262f3b772ffbf73cad588c3ae3d7f031
MD5 9aaf978bd9dce8fa807d2b2f59f8b6be
BLAKE2b-256 06c0154f2ba59da345cf3a7eccf767da641a2698ebf1972c3f005a8a8c068076

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for case_class-0.0.4.macosx-10.11-x86_64.tar.gz
Algorithm Hash digest
SHA256 37dccd8aef657ea4ccde9aa6409c43f64302b154332f25f123e3b03d0ed16503
MD5 e4069de7b4521c2c099e8a37abc8df7a
BLAKE2b-256 b52bffeb69af7963ddc28d3844c8dcc5109a00272afe5fb73a60c734c7174208

See more details on using hashes here.

File details

Details for the file case_class-0.0.4-py3.5.egg.

File metadata

  • Download URL: case_class-0.0.4-py3.5.egg
  • Upload date:
  • Size: 15.5 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for case_class-0.0.4-py3.5.egg
Algorithm Hash digest
SHA256 da5e0326ab7d4909e70cc79952bd890c17566cfae6f6208ab1f60284ef4c71c8
MD5 d3ce82fb04ce3acac7633626e1a03f33
BLAKE2b-256 834d5e28de82ac43e1fe2045907f36e0f0cc6c1be36d479a0d6c63fe151bed5f

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for case_class-0.0.4-py2.7.egg
Algorithm Hash digest
SHA256 5a9f6286a3391cd5f57406f39f8b366169115c29ebb1ebe9b593403c95c7c961
MD5 32b06ef155d25a737557f60e704bdc19
BLAKE2b-256 316b139de9fc8eb0ae44f09f63772dfe11fcd876daa3c267420830683a78d16a

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