dataclasses


Namedataclasses JSON
Version 0.8 PyPI version JSON
download
home_pagehttps://github.com/ericvsmith/dataclasses
SummaryA backport of the dataclasses module for Python 3.6
upload_time2020-11-13 14:40:30
maintainer
docs_urlNone
authorEric V. Smith
requires_python>=3.6, <3.7
licenseApache
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            .. image:: https://img.shields.io/pypi/v/dataclasses.svg
   :target: https://pypi.org/project/dataclasses/


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        |
+---------+------------+-------------------------------------+



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ericvsmith/dataclasses",
    "name": "dataclasses",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6, <3.7",
    "maintainer_email": "",
    "keywords": "",
    "author": "Eric V. Smith",
    "author_email": "eric@python.org",
    "download_url": "https://files.pythonhosted.org/packages/1f/12/7919c5d8b9c497f9180db15ea8ead6499812ea8264a6ae18766d93c59fe5/dataclasses-0.8.tar.gz",
    "platform": "",
    "description": ".. image:: https://img.shields.io/pypi/v/dataclasses.svg\n   :target: https://pypi.org/project/dataclasses/\n\n\nThis is an implementation of PEP 557, Data Classes.  It is a backport\nfor Python 3.6.  Because dataclasses will be included in Python 3.7,\nany discussion of dataclass features should occur on the python-dev\nmailing list at https://mail.python.org/mailman/listinfo/python-dev.\nAt this point this repo should only be used for historical purposes\n(it's where the original dataclasses discussions took place) and for\ndiscussion of the actual backport to Python 3.6.\n\nSee https://www.python.org/dev/peps/pep-0557/ for the details of how\nData Classes work.\n\nA test file can be found at\nhttps://github.com/ericvsmith/dataclasses/blob/master/test/test_dataclasses.py,\nor in the sdist file.\n\nInstallation\n-------------\n\n.. code-block::\n\n  pip install dataclasses\n\n\nExample Usage\n-------------\n\n.. code-block:: python\n\n  from dataclasses import dataclass\n\n  @dataclass\n  class InventoryItem:\n      name: str\n      unit_price: float\n      quantity_on_hand: int = 0\n\n      def total_cost(self) -> float:\n          return self.unit_price * self.quantity_on_hand\n\n  item = InventoryItem('hammers', 10.49, 12)\n  print(item.total_cost())\n\nSome additional tools can be found in dataclass_tools.py, included in\nthe sdist.\n\nCompatibility\n-------------\n\nThis backport assumes that dict objects retain their insertion order.\nThis is true in the language spec for Python 3.7 and greater.  Since\nthis is a backport to Python 3.6, it raises an interesting question:\ndoes that guarantee apply to 3.6?  For CPython 3.6 it does.  As of the\ntime of this writing, it's also true for all other Python\nimplementations that claim to be 3.6 compatible, of which there are\nnone.  Any new 3.6 implementations are expected to have ordered dicts.\nSee the analysis at the end of this email:\n\nhttps://mail.python.org/pipermail/python-dev/2017-December/151325.html\n\nAs of version 0.4, this code no longer works with Python 3.7. For 3.7,\nuse the built-in dataclasses module.\n\nRelease History\n---------------\n\n+---------+------------+-------------------------------------+\n| Version | Date       | Description                         |\n+=========+============+=====================================+\n| 0.8     | 2020-11-13 | Fix ClassVar in .replace()          |\n+---------+------------+-------------------------------------+\n| 0.7     | 2019-10-20 | Require python 3.6 only             |\n+---------+------------+-------------------------------------+\n| 0.6     | 2018-05-17 | Equivalent to Python 3.7.0rc1       |\n+---------+------------+-------------------------------------+\n| 0.5     | 2018-03-28 | Equivalent to Python 3.7.0b3        |\n+---------+------------+-------------------------------------+\n\n\n",
    "bugtrack_url": null,
    "license": "Apache",
    "summary": "A backport of the dataclasses module for Python 3.6",
    "version": "0.8",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "0d6e5bb7adcc8fb0de3ef1ace1b32999",
                "sha256": "0201d89fa866f68c8ebd9d08ee6ff50c0b255f8ec63a71c16fda7af82bb887bf"
            },
            "downloads": -1,
            "filename": "dataclasses-0.8-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0d6e5bb7adcc8fb0de3ef1ace1b32999",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6, <3.7",
            "size": 19041,
            "upload_time": "2020-11-13T14:40:29",
            "upload_time_iso_8601": "2020-11-13T14:40:29.194010Z",
            "url": "https://files.pythonhosted.org/packages/fe/ca/75fac5856ab5cfa51bbbcefa250182e50441074fdc3f803f6e76451fab43/dataclasses-0.8-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "c9a52e322ada1406bfde9ebe3cdbbcca",
                "sha256": "8479067f342acf957dc82ec415d355ab5edb7e7646b90dc6e2fd1d96ad084c97"
            },
            "downloads": -1,
            "filename": "dataclasses-0.8.tar.gz",
            "has_sig": false,
            "md5_digest": "c9a52e322ada1406bfde9ebe3cdbbcca",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6, <3.7",
            "size": 36581,
            "upload_time": "2020-11-13T14:40:30",
            "upload_time_iso_8601": "2020-11-13T14:40:30.139527Z",
            "url": "https://files.pythonhosted.org/packages/1f/12/7919c5d8b9c497f9180db15ea8ead6499812ea8264a6ae18766d93c59fe5/dataclasses-0.8.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2020-11-13 14:40:30",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "ericvsmith",
    "github_project": "dataclasses",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "dataclasses"
}
        
Elapsed time: 0.03483s