dataclasses-xargs


Namedataclasses-xargs JSON
Version 1.0.2 PyPI version JSON
download
home_pagehttps://github.com/scheibling/dataclasses-xargs.git
SummaryAn extension to the python dataclasses package that enables you to push the *args/*xargs
upload_time2023-10-13 09:20:13
maintainer
docs_urlNone
authorLars Scheibling
requires_python>=3.7
licenseGPLv3
keywords python dataclass args xargs
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # dataclasses-xargs
An extension to the dataclasses library allowing you to push your unnamed parameters to a specific field.

## Installation
```bash
pip3 install dataclasses-xargs
```

# Usage Example
```python
from dataclasses_xargs import dataclass

@dataclass
class FailTest(object):
    a: int = None
    b: str = None
    c: list = None

@dataclass(xarg_field="c")
class SuccessTest(object):
    a: int = None
    b: str = None
    c: list = None

# When xarg_field is not defined, dataclasses work as normal and will throw an error if you pass in double parameters
try:
    FailTest(1, 2, 3, 4, 5, a=1, b="b")
except TypeError as e:
    assert e.args[0] == "FailTest.__init__() got multiple values for argument 'a'"

# When defined, and the xarg_field is not passed as a named parameter, all unnamed parameters will be pushed to the xarg_field.
# Note that the xarg_field still needs to be defined in the class, see above.
dcl = SuccessTest(1, 2, 3, 4, 5, a=1, b="b")
print(dcl)
"""
SuccessTest(a=1, b='b', c=(1, 2, 3, 4, 5))
"""
assert dcl.a == 1
assert dcl.b == "b"
assert dcl.c == (1, 2, 3, 4, 5)

dcl = SuccessTest(1, 2, 3, 4, 5, a=1, b="b", c=[0, 0, 0])
print(dcl)
"""
SuccessTest(a=1, b='b', c=[0, 0, 0])
"""
assert dcl.a == 1
assert dcl.b == "b"
assert dcl.c == [0, 0, 0]

exit(0)
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/scheibling/dataclasses-xargs.git",
    "name": "dataclasses-xargs",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "python dataclass args xargs",
    "author": "Lars Scheibling",
    "author_email": "it@scheibling.se",
    "download_url": "https://files.pythonhosted.org/packages/c2/10/48897485316205da3feeae02348415513b1d73a8f5a4eb29fc21b851d456/dataclasses_xargs-1.0.2.tar.gz",
    "platform": null,
    "description": "# dataclasses-xargs\nAn extension to the dataclasses library allowing you to push your unnamed parameters to a specific field.\n\n## Installation\n```bash\npip3 install dataclasses-xargs\n```\n\n# Usage Example\n```python\nfrom dataclasses_xargs import dataclass\n\n@dataclass\nclass FailTest(object):\n    a: int = None\n    b: str = None\n    c: list = None\n\n@dataclass(xarg_field=\"c\")\nclass SuccessTest(object):\n    a: int = None\n    b: str = None\n    c: list = None\n\n# When xarg_field is not defined, dataclasses work as normal and will throw an error if you pass in double parameters\ntry:\n    FailTest(1, 2, 3, 4, 5, a=1, b=\"b\")\nexcept TypeError as e:\n    assert e.args[0] == \"FailTest.__init__() got multiple values for argument 'a'\"\n\n# When defined, and the xarg_field is not passed as a named parameter, all unnamed parameters will be pushed to the xarg_field.\n# Note that the xarg_field still needs to be defined in the class, see above.\ndcl = SuccessTest(1, 2, 3, 4, 5, a=1, b=\"b\")\nprint(dcl)\n\"\"\"\nSuccessTest(a=1, b='b', c=(1, 2, 3, 4, 5))\n\"\"\"\nassert dcl.a == 1\nassert dcl.b == \"b\"\nassert dcl.c == (1, 2, 3, 4, 5)\n\ndcl = SuccessTest(1, 2, 3, 4, 5, a=1, b=\"b\", c=[0, 0, 0])\nprint(dcl)\n\"\"\"\nSuccessTest(a=1, b='b', c=[0, 0, 0])\n\"\"\"\nassert dcl.a == 1\nassert dcl.b == \"b\"\nassert dcl.c == [0, 0, 0]\n\nexit(0)\n```\n",
    "bugtrack_url": null,
    "license": "GPLv3",
    "summary": "An extension to the python dataclasses package that enables you to push the *args/*xargs",
    "version": "1.0.2",
    "project_urls": {
        "Homepage": "https://github.com/scheibling/dataclasses-xargs.git"
    },
    "split_keywords": [
        "python",
        "dataclass",
        "args",
        "xargs"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3bc808567c8e3113fba85aff30a35896c4951238d1d947641faaca4b4ca76102",
                "md5": "34db8f9d1430497657d176646462e9a5",
                "sha256": "11e31dfad81faa477f2e26c3f63fafb0ed16ae47eace42800b6db280c91d86b5"
            },
            "downloads": -1,
            "filename": "dataclasses_xargs-1.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "34db8f9d1430497657d176646462e9a5",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 19967,
            "upload_time": "2023-10-13T09:20:11",
            "upload_time_iso_8601": "2023-10-13T09:20:11.710292Z",
            "url": "https://files.pythonhosted.org/packages/3b/c8/08567c8e3113fba85aff30a35896c4951238d1d947641faaca4b4ca76102/dataclasses_xargs-1.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c21048897485316205da3feeae02348415513b1d73a8f5a4eb29fc21b851d456",
                "md5": "54c6d818efffbcdbb4cdb0cfd370f10d",
                "sha256": "8d32a07afbe8368b47ab672572a391f3483e5d9c8ffa226cce41699bdc3070f4"
            },
            "downloads": -1,
            "filename": "dataclasses_xargs-1.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "54c6d818efffbcdbb4cdb0cfd370f10d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 19932,
            "upload_time": "2023-10-13T09:20:13",
            "upload_time_iso_8601": "2023-10-13T09:20:13.853269Z",
            "url": "https://files.pythonhosted.org/packages/c2/10/48897485316205da3feeae02348415513b1d73a8f5a4eb29fc21b851d456/dataclasses_xargs-1.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-13 09:20:13",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "scheibling",
    "github_project": "dataclasses-xargs",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "dataclasses-xargs"
}
        
Elapsed time: 0.53952s