Skip to main content

A backport of the dataclasses module for Python 3.6

Project description

https://img.shields.io/pypi/v/dataclasses.svg

This is an implementation of PEP 557, Data Classes. It is a backport for Python 3.6. Because dataclasses will be included in Python 3.7, any discussion of dataclass features should occur on the python-dev mailing list at https://mail.python.org/mailman/listinfo/python-dev. At this point this repo should only be used for historical purposes (it’s where the original dataclasses discussions took place) and for discussion of the actual backport to Python 3.6.

See https://www.python.org/dev/peps/pep-0557/ for the details of how Data Classes work.

A test file can be found at https://github.com/ericvsmith/dataclasses/blob/master/test/test_dataclasses.py, or in the sdist file.

Installation

pip install dataclasses

Example Usage

from dataclasses import dataclass

@dataclass
class InventoryItem:
    name: str
    unit_price: float
    quantity_on_hand: int = 0

    def total_cost(self) -> float:
        return self.unit_price * self.quantity_on_hand

item = InventoryItem('hammers', 10.49, 12)
print(item.total_cost())

Some additional tools can be found in dataclass_tools.py, included in the sdist.

Compatibility

This backport assumes that dict objects retain their sort order. This is true in the language spec for Python 3.7 and greater. Since this is a backport to Python 3.6, it raises an interesting question: does that guarantee apply to 3.6? For CPython 3.6 it does. As of the time of this writing, it’s also true for all other Python implementations that claim to be 3.6 compatible, of which there are none. Any new 3.6 implementations are expected to have ordered dicts. See the analysis at the end of this email:

https://mail.python.org/pipermail/python-dev/2017-December/151325.html

As of version 0.4, this code no longer works with Python 3.7. For 3.7, use the built-in dataclasses module.

Release History

Version

Date

Description

0.7

2019-10-20

Require python 3.6 only

0.6

2018-05-17

Equivalent to Python 3.7.0rc1

0.5

2018-03-28

Equivalent to Python 3.7.0b3

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

dataclasses-0.7.tar.gz (35.7 kB view details)

Uploaded Source

Built Distribution

dataclasses-0.7-py3-none-any.whl (19.0 kB view details)

Uploaded Python 3

File details

Details for the file dataclasses-0.7.tar.gz.

File metadata

  • Download URL: dataclasses-0.7.tar.gz
  • Upload date:
  • Size: 35.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

File hashes

Hashes for dataclasses-0.7.tar.gz
Algorithm Hash digest
SHA256 494a6dcae3b8bcf80848eea2ef64c0cc5cd307ffc263e17cdf42f3e5420808e6
MD5 969e12cac2b69ddc280758f76b481372
BLAKE2b-256 7a71fdbab71f1f714e03ead2d264bf444f88379bc09b2937d54ec83894057f80

See more details on using hashes here.

File details

Details for the file dataclasses-0.7-py3-none-any.whl.

File metadata

  • Download URL: dataclasses-0.7-py3-none-any.whl
  • Upload date:
  • Size: 19.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

File hashes

Hashes for dataclasses-0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 3459118f7ede7c8bea0fe795bff7c6c2ce287d01dd226202f7c9ebc0610a7836
MD5 6f2bb66b4815b820a78a47792ffce4c6
BLAKE2b-256 e1d26f02df2616fd4016075f60157c7a0452b38d8f7938ae94343911e0fb0b09

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page