Scala-like CaseClasses for Python
Project description
# PythonCaseClass
[](https://travis-ci.org/tkw1536/PythonCaseClass)
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
[the Python Package Index](https://pypi.python.org/pypi/case_class).
Installation can be done simply via pip:
```bash
pip install case_class
```
Alternatively, clone this repository and run setup.py:
```bash
git clone https://github.com/tkw1536/PythonCaseClass
python setup.py install
```
## Examples
```python
# 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](example.py).
## License + Acknowledgements
This module and associated documentation is Copyright © Tom Wiesing 2016
and licensed under the MIT license, see [LICENSE](license) for details. Small
parts of the code are adapted from the [six](https://pypi.python.org/pypi/six)
module, which is Copyright © 2010-2015 Benjamin Peterson.
[](https://travis-ci.org/tkw1536/PythonCaseClass)
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
[the Python Package Index](https://pypi.python.org/pypi/case_class).
Installation can be done simply via pip:
```bash
pip install case_class
```
Alternatively, clone this repository and run setup.py:
```bash
git clone https://github.com/tkw1536/PythonCaseClass
python setup.py install
```
## Examples
```python
# 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](example.py).
## License + Acknowledgements
This module and associated documentation is Copyright © Tom Wiesing 2016
and licensed under the MIT license, see [LICENSE](license) for details. Small
parts of the code are adapted from the [six](https://pypi.python.org/pypi/six)
module, which is Copyright © 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.2.tar.gz
(7.7 kB
view details)
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
case_class-0.0.2-py3.5.egg
(15.8 kB
view details)
case_class-0.0.2-py2.7.egg
(15.7 kB
view details)
File details
Details for the file case_class-0.0.2.tar.gz.
File metadata
- Download URL: case_class-0.0.2.tar.gz
- Upload date:
- Size: 7.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
610aaf8eff1ae93c2b6880e39a02819b468e405fdfc58a175d4c80f63fc5461b
|
|
| MD5 |
40fb10eaf09383dff19575032fc4948d
|
|
| BLAKE2b-256 |
ee29f06db6a4791933131a88297a5d4b39c89ff025d184478a43fff17eb24e46
|
File details
Details for the file case_class-0.0.2-py3.5.egg.
File metadata
- Download URL: case_class-0.0.2-py3.5.egg
- Upload date:
- Size: 15.8 kB
- Tags: Egg
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
42f20009fd7d8feaff405c4beab3c4c82123553f626d9cc9a72e90d3807f0c8e
|
|
| MD5 |
ba260b498827e482a52c4ed8dfd5c8e2
|
|
| BLAKE2b-256 |
7c2a0e5d336e23ef47958aa6293afccdc9064af93aa2968ae5bd1aaba9d0a5cf
|
File details
Details for the file case_class-0.0.2-py2.7.egg.
File metadata
- Download URL: case_class-0.0.2-py2.7.egg
- Upload date:
- Size: 15.7 kB
- Tags: Egg
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
921dd03af445d5eb7898b574ebc9649fe274c7c57fe1e44de7c79ef13cc38b8b
|
|
| MD5 |
2c1816c3c367b23d8e2123af7256f7df
|
|
| BLAKE2b-256 |
51da0af3999d5b4c5e77ccd986c141cd72edc92abe98519a67d53e262430e69e
|