Skip to main content
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.

Release files for case_class 0.0.8

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

Source distribution (sdist)

Source distribution for case_class 0.0.8
File Size Uploaded
case_class-0.0.8.tar.gz 12.2 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for case_class 0.0.8
File Interpreter ABI Platform
case_class-0.0.8-py3-none-any.whl Python 3 none any Details
case_class-0.0.8-py2-none-any.whl Python 2 none any Details

Total release size: 42.3 kB

Release files / case_class-0.0.8.tar.gz

Download URL case_class-0.0.8.tar.gz
Size 12.2 kB
Tags Source
SHA-256 checksum
How to use checksums
e30dac2da923c6afa296b5342fbd38c76c03803c4b3ccc8d3d2236671794931a
BLAKE2b-256 checksum
How to use checksums
2aac76c5b462cf10c1c09b6c50f65d9d3de99fa7497c38ca5ca75ec77ae2015e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / case_class-0.0.8-py3-none-any.whl

Download URL case_class-0.0.8-py3-none-any.whl
Size 15.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aba2402856294f066fe8bcdceb9103e3b51acfdf009ba36a967b82a87404684b
BLAKE2b-256 checksum
How to use checksums
aea8769a7c470e5f982796883cc92b0a83bb018b7814d8a8bb1353c0e5cfc937
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / case_class-0.0.8-py2-none-any.whl

Download URL case_class-0.0.8-py2-none-any.whl
Size 15.0 kB
Tags Python 2
SHA-256 checksum
How to use checksums
613645edd7a7472d064e5c22a0f15eaab3fb41355560a6dd2e648eb59ecd7ede
BLAKE2b-256 checksum
How to use checksums
38b1132bb9e4846d77f75b6c7a22fbe022cdc734b439be58d7eb6f55e9d992a0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.0.8 This release

3 release files

0.0.7

4 release files

0.0.6

4 release files

0.0.5

4 release files

0.0.4

4 release files

0.0.3

3 release files

0.0.2

3 release files

0.0.1

3 release files

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