dataclasses

Latest version: 0.8 registry icon
Maintenance score
0
Safety score
0
Popularity score
22
Check your open source dependency risks. Get immediate insight about security, stability and licensing risks.
Security
  Vulnerabilities
Version Suggest Low Medium High Critical
0.8 0 0 0 0 0
0.7 0 0 0 0 0
0.6 0 0 0 0 0
0.5 0 0 0 0 0
0.4 0 0 0 0 0
0.3 0 0 0 0 0
0.2 0 0 0 0 0
0.1 0 0 0 0 0

Stability
Latest release:

0.8 - This version may not be safe as it has not been updated for a long time. Find out if your coding project uses this component and get notified of any reported security vulnerabilities with Meterian-X Open Source Security Platform

Licensing

Maintain your licence declarations and avoid unwanted licences to protect your IP the way you intended.

Apache-1.0   -   Apache License 1.0

Not a wildcard

Not proprietary

OSI Compliant



.. image:: https://img.shields.io/pypi/v/dataclasses.svg :target: https://pypi.org/project/dataclasses/

Copyright 2017-2022 Eric V. Smith, all rights reserved.

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

.. code-block::

pip install dataclasses

Example Usage

.. code-block:: python

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 insertion 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.8 | 2020-11-13 | Fix ClassVar in .replace() | +---------+------------+-------------------------------------+ | 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 | +---------+------------+-------------------------------------+