https://github.com/user0332/py-default
Uniform Default Values for Python
https://github.com/user0332/py-default
Last synced: 4 months ago
JSON representation
Uniform Default Values for Python
- Host: GitHub
- URL: https://github.com/user0332/py-default
- Owner: User0332
- License: mit
- Created: 2024-12-18T20:08:11.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-19T15:36:04.000Z (over 1 year ago)
- Last Synced: 2025-01-19T04:55:38.902Z (over 1 year ago)
- Language: Python
- Homepage:
- Size: 13.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PyDefault - Uniform Default Values for Python
PyDefault allows for uniform assignment/generation of default values for common types in Python. The API comes in two forms - a function and a map.
## Installation
You can install `pydefault` using `pip` via `pip install py-default`, or you may install it using `pip` using the GitHub repo URL. Distributions are also available from `dist/` at the root of the repository.
## Function API
```py
from pydefault import default
class Person: ...
mynum = default(int) # initializes to 0
empty_list = default(list) # initializes to []
obj = default(Person) # initializes to None
```
## Map API
```py
from pydefault import default
class Person: ...
mynum = default[int] # initializes to 0
empty_list = default[list] # initializes to []
obj = default[Person] # initializes to None
```
## Default Values
The following types resolve to the following default values:
- `int` -> `0`
- `bool` -> `0` (`False`)
- `complex` -> `complex()`
- `str` -> `""`
- `float` -> `0.0`
- `list` -> `[]`
- `set` -> `set()`
- `dict` -> `{}`
- anything else -> `None`