simple-elements 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- simple_elements/__init__.py +18 -0
- simple_elements/sentinels/UNSET.py +73 -0
- simple_elements/sentinels/__init__.py +14 -0
- simple_elements-0.1.0.dist-info/METADATA +113 -0
- simple_elements-0.1.0.dist-info/RECORD +8 -0
- simple_elements-0.1.0.dist-info/WHEEL +5 -0
- simple_elements-0.1.0.dist-info/licenses/LICENSE +21 -0
- simple_elements-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from .sentinels import UnsetType, UNSET
|
|
2
|
+
|
|
3
|
+
__all__ = [
|
|
4
|
+
# Sentinel
|
|
5
|
+
"UnsetType",
|
|
6
|
+
"UNSET",
|
|
7
|
+
]
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
_DESIGN_NOTES = """
|
|
11
|
+
# simple_elements
|
|
12
|
+
|
|
13
|
+
## Public API
|
|
14
|
+
| Name | Description |
|
|
15
|
+
|--------------------------------|-------------------------------------------------------------------|
|
|
16
|
+
| `UNSET` | Sentinel for an unset value |
|
|
17
|
+
| `UnsetType` | Sentinel type — for type annotations |
|
|
18
|
+
"""
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
from typing import Final
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class UnsetType:
|
|
5
|
+
"""Singleton sentinel type representing an unset value."""
|
|
6
|
+
|
|
7
|
+
# Attribute for the singleton instance
|
|
8
|
+
_instance = None
|
|
9
|
+
|
|
10
|
+
# Create the singleton instance
|
|
11
|
+
def __new__(cls):
|
|
12
|
+
if cls._instance is None:
|
|
13
|
+
cls._instance = super().__new__(cls)
|
|
14
|
+
return cls._instance
|
|
15
|
+
|
|
16
|
+
def __repr__(self):
|
|
17
|
+
return "UNSET"
|
|
18
|
+
|
|
19
|
+
def __bool__(self):
|
|
20
|
+
return False
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
# Sentinel
|
|
24
|
+
UNSET: Final = UnsetType()
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
_DESIGN_NOTES = """
|
|
28
|
+
# UnsetType and UNSET
|
|
29
|
+
|
|
30
|
+
## Purpose
|
|
31
|
+
A sentinel for distinguishing an unset value from an intentionally passed `None` —
|
|
32
|
+
because `None` is a valid Python value with its own meaning.
|
|
33
|
+
|
|
34
|
+
## Why not None?
|
|
35
|
+
```python
|
|
36
|
+
def func(value = None):
|
|
37
|
+
if value is None:
|
|
38
|
+
# ambiguous — was None passed intentionally, or was the parameter not provided at all?
|
|
39
|
+
```
|
|
40
|
+
```python
|
|
41
|
+
def func(value: UnsetType = UNSET):
|
|
42
|
+
if value is UNSET:
|
|
43
|
+
# parameter was not provided → apply default behaviour
|
|
44
|
+
elif value is None:
|
|
45
|
+
# None was passed intentionally → specific logic applies
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Singleton
|
|
49
|
+
`UnsetType` is implemented as a singleton — all instances are identical.
|
|
50
|
+
Comparisons must therefore always use `is`, never `==`:
|
|
51
|
+
```python
|
|
52
|
+
value is UNSET # ✓ correct
|
|
53
|
+
value == UNSET # ✗ never do this
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## __bool__
|
|
57
|
+
`UnsetType.__bool__` returns `False` — `UNSET` therefore behaves as a falsy value:
|
|
58
|
+
```python
|
|
59
|
+
if not value:
|
|
60
|
+
# true for UNSET, None, False, "", and 0
|
|
61
|
+
```
|
|
62
|
+
For an explicit check, always use `is UNSET`.
|
|
63
|
+
|
|
64
|
+
## UNSET
|
|
65
|
+
A pre-created singleton instance of `UnsetType` — serves as a shared primitive
|
|
66
|
+
across the entire simple-libs ecosystem. Every library that needs to distinguish
|
|
67
|
+
an unset parameter from `None` imports it from here.
|
|
68
|
+
|
|
69
|
+
## Notes
|
|
70
|
+
- The `Final` annotation ensures that `UNSET` cannot be reassigned.
|
|
71
|
+
- Both objects (`UnsetType` and `UNSET`) are exported from the library —
|
|
72
|
+
users may use them in their own type annotations and checks.
|
|
73
|
+
"""
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from .UNSET import UnsetType, UNSET
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
_DESIGN_NOTES = """
|
|
5
|
+
# utils/sentinel
|
|
6
|
+
|
|
7
|
+
## Contents
|
|
8
|
+
The simple library's sentinel values — exported from the library and available to users.
|
|
9
|
+
|
|
10
|
+
| Name | Description |
|
|
11
|
+
|-------------|--------------------------------------------------------------|
|
|
12
|
+
| `UnsetType` | Singleton type representing an unset value |
|
|
13
|
+
| `UNSET` | A pre-created instance of `UnsetType` — used throughout |
|
|
14
|
+
"""
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: simple-elements
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Lightweight utilities and helpers shared across the simple-libs ecosystem.
|
|
5
|
+
Author-email: "Dalibor Sova (Sudip2708)" <daliborsova@seznam.cz>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/simple-libs/simple-elements
|
|
8
|
+
Project-URL: Repository, https://github.com/simple-libs/simple-elements
|
|
9
|
+
Project-URL: Issues, https://github.com/simple-libs/simple-elements/issues
|
|
10
|
+
Project-URL: Changelog, https://github.com/simple-libs/simple-elements/blob/main/CHANGELOG.md
|
|
11
|
+
Keywords: utilities,helpers,sentinel,tools,simple-libs
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
19
|
+
Requires-Python: >=3.11
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Provides-Extra: dev
|
|
23
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
|
|
26
|
+
# simple-elements
|
|
27
|
+
|
|
28
|
+
> Lightweight utilities and helpers shared across the simple-libs ecosystem —
|
|
29
|
+
> each one self-contained and usable independently in any Python project.
|
|
30
|
+
|
|
31
|
+

|
|
32
|
+

|
|
33
|
+

|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## Contents
|
|
38
|
+
|
|
39
|
+
- [Installation](#installation)
|
|
40
|
+
- [Sentinels](#sentinels)
|
|
41
|
+
- [About the Simple ecosystem](#about-the-simple-ecosystem)
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## Installation
|
|
46
|
+
```bash
|
|
47
|
+
pip install simple-elements
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## Sentinels
|
|
53
|
+
|
|
54
|
+
### UNSET and UnsetType
|
|
55
|
+
|
|
56
|
+
A sentinel for distinguishing an unset value from an intentionally passed
|
|
57
|
+
`None` — because `None` is a valid Python value with its own meaning.
|
|
58
|
+
Evaluates as `False` in a boolean context:
|
|
59
|
+
```python
|
|
60
|
+
from simple_elements import UNSET, UnsetType
|
|
61
|
+
|
|
62
|
+
def connect(host: str, timeout: int | UnsetType = UNSET):
|
|
63
|
+
if timeout is UNSET:
|
|
64
|
+
timeout = get_default_timeout() # not provided → use default
|
|
65
|
+
elif timeout is None:
|
|
66
|
+
timeout = 0 # None passed intentionally → no timeout
|
|
67
|
+
|
|
68
|
+
if not UNSET:
|
|
69
|
+
print("UNSET is falsy ✓") # True — bool(UNSET) == False
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Comparison must always use `is`, never `==`:
|
|
73
|
+
```python
|
|
74
|
+
value is UNSET # ✓ correct
|
|
75
|
+
value == UNSET # ✗ never do this
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## About the Simple ecosystem
|
|
81
|
+
|
|
82
|
+
`simple-elements` is part of the **Simple ecosystem** — a collection of small,
|
|
83
|
+
self-contained Python libraries. Each one solves exactly one thing — but all
|
|
84
|
+
of them share a common philosophy:
|
|
85
|
+
|
|
86
|
+
**Dyslexia-friendly** — minimise mental load. Atomise code into self-contained
|
|
87
|
+
units, name files after the logic they contain, write explanations that describe
|
|
88
|
+
*why* — not just *what*.
|
|
89
|
+
|
|
90
|
+
**Programmer's zen** — nothing should be missing and nothing should be
|
|
91
|
+
superfluous. The journey is the destination: code should be fully understood;
|
|
92
|
+
better to go slowly and correctly than quickly and with mistakes. The
|
|
93
|
+
crystallisation approach — not perfection on the first try, but gradual
|
|
94
|
+
refinement towards it.
|
|
95
|
+
|
|
96
|
+
**Defensive style** — anticipate all possible failure modes so that only safe
|
|
97
|
+
paths remain. Never raise unexpected errors; degrade gracefully.
|
|
98
|
+
|
|
99
|
+
**Minimalism** — find the path to the goal in as few steps as possible, but
|
|
100
|
+
leave nothing out. Each file has one responsibility.
|
|
101
|
+
|
|
102
|
+
**Code as craft** — code should be pleasant to look at and evoke a sense of
|
|
103
|
+
harmony. Treat code as a small work of art — like a carpenter carving a
|
|
104
|
+
sculpture. Optimise for the user: everything should make sense without having
|
|
105
|
+
to study the documentation at length.
|
|
106
|
+
|
|
107
|
+
These are aspirations — a sense of direction. And that is exactly what the
|
|
108
|
+
note about the journey becoming the destination is all about. 🙂
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
*The library is covered by tests across all modules. Tests are part of the
|
|
113
|
+
repository and serve as living documentation of the expected behaviour.*
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
simple_elements/__init__.py,sha256=5_ZiGrCSW5u28MEeSD7DoNZ4aZPxtAyzOfRCPCLcm7o,589
|
|
2
|
+
simple_elements/sentinels/UNSET.py,sha256=V3_WOAfNd6IZAIlfBvt0rbTUwjBu21iaz2OJ1Vy1AWI,2049
|
|
3
|
+
simple_elements/sentinels/__init__.py,sha256=EavHIqw4833901oVv_UWqMO71CXJdnzeDBjGJ6WWV_4,514
|
|
4
|
+
simple_elements-0.1.0.dist-info/licenses/LICENSE,sha256=S47IxnGIoMNACXzGEKr80I6y6FKOcIJga-o57WTKfCg,1100
|
|
5
|
+
simple_elements-0.1.0.dist-info/METADATA,sha256=Y5V_fy-W-loX9ocRoFPuBHI4TsrpwifF1U180xWMGI0,4162
|
|
6
|
+
simple_elements-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
7
|
+
simple_elements-0.1.0.dist-info/top_level.txt,sha256=1ki5IH-Ko7C1xNo33v8U61Mx0L9DnyeUamIDHbgXNGM,16
|
|
8
|
+
simple_elements-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Dalibor Sova (Sudip2708)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
simple_elements
|