py-prim 0.1.0__tar.gz
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.
- py_prim-0.1.0/LICENSE +21 -0
- py_prim-0.1.0/PKG-INFO +93 -0
- py_prim-0.1.0/README.md +80 -0
- py_prim-0.1.0/pyproject.toml +16 -0
- py_prim-0.1.0/setup.cfg +4 -0
- py_prim-0.1.0/src/primitives/__init__.py +10 -0
- py_prim-0.1.0/src/primitives/core.py +129 -0
- py_prim-0.1.0/src/py_prim.egg-info/PKG-INFO +93 -0
- py_prim-0.1.0/src/py_prim.egg-info/SOURCES.txt +9 -0
- py_prim-0.1.0/src/py_prim.egg-info/dependency_links.txt +1 -0
- py_prim-0.1.0/src/py_prim.egg-info/top_level.txt +1 -0
py_prim-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Salik
|
|
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 all
|
|
13
|
+
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 THE
|
|
21
|
+
SOFTWARE.
|
py_prim-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: py-prim
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Enhanced and validated base primitive data types for Python.
|
|
5
|
+
Author: Salik Tariq
|
|
6
|
+
Classifier: Programming Language :: Python :: 3
|
|
7
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
8
|
+
Classifier: Operating System :: OS Independent
|
|
9
|
+
Requires-Python: >=3.7
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Dynamic: license-file
|
|
13
|
+
|
|
14
|
+
# py-prim
|
|
15
|
+
A robust, validated, and state-aware base class architecture for standard Python primitive data types.
|
|
16
|
+
|
|
17
|
+
In standard Python, primitives like int and str are loose and allow for silent state changes or type mixing. This package provides wrapper classes (Integer, String, etc.) that enforce strict type validation, provide standardized empty/null checks, and offer a consistent API across all basic data types.
|
|
18
|
+
|
|
19
|
+
## Features
|
|
20
|
+
Strict Type Validation: Fails fast if you try to assign a string to an integer, or mix up booleans and ints.
|
|
21
|
+
|
|
22
|
+
Standardized API: Every type implements .is_empty(), .is_null(), and .reset().
|
|
23
|
+
|
|
24
|
+
Magic Methods Support: Compares cleanly with standard Python types using == and integrates seamlessly with if statements.
|
|
25
|
+
|
|
26
|
+
Zero Dependencies: Built entirely on the Python standard library.
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
You can install this package directly from GitHub using either pip or uv.
|
|
30
|
+
|
|
31
|
+
Using pip:
|
|
32
|
+
|
|
33
|
+
pip install git+[https://github.com/saliktariq/Py-Prim.git](https://github.com/saliktariq/Py-Prim.git)
|
|
34
|
+
|
|
35
|
+
Using uv:
|
|
36
|
+
|
|
37
|
+
uv pip install git+[https://github.com/saliktariq/Py-Prim.git](https://github.com/saliktariq/Py-Prim.git)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
## Available Types
|
|
41
|
+
All types inherit from the Primitive abstract base class:
|
|
42
|
+
|
|
43
|
+
- Integer
|
|
44
|
+
- Float
|
|
45
|
+
- String
|
|
46
|
+
- Boolean
|
|
47
|
+
- Bytes
|
|
48
|
+
|
|
49
|
+
## Usage:
|
|
50
|
+
|
|
51
|
+
Access and mutate the underlying data using the .value property.
|
|
52
|
+
|
|
53
|
+
from primitives import Integer, String
|
|
54
|
+
|
|
55
|
+
### Initialize with a value
|
|
56
|
+
age = Integer(25)
|
|
57
|
+
print(age.value) # 25
|
|
58
|
+
|
|
59
|
+
### Change the value
|
|
60
|
+
age.value = 26
|
|
61
|
+
Strict Type Validation
|
|
62
|
+
The classes automatically validate types upon initialization and assignment, preventing accidental type mixing.
|
|
63
|
+
|
|
64
|
+
from primitives import Integer
|
|
65
|
+
|
|
66
|
+
score = Integer(100)
|
|
67
|
+
|
|
68
|
+
#### This will raise a ValueError: "Invalid value for Integer: 100.5"
|
|
69
|
+
score.value = 100.5
|
|
70
|
+
|
|
71
|
+
### This library strictly isolates Booleans from Integers.
|
|
72
|
+
score.value = True # Raises ValueError
|
|
73
|
+
State Checks and Resets
|
|
74
|
+
Every type knows what its "empty" and "default" states are.
|
|
75
|
+
|
|
76
|
+
from primitives import String, Float
|
|
77
|
+
|
|
78
|
+
name = String("")
|
|
79
|
+
print(name.is_empty()) # True
|
|
80
|
+
|
|
81
|
+
name.value = "Alice"
|
|
82
|
+
print(name.is_empty()) # False
|
|
83
|
+
|
|
84
|
+
### Reset back to the type's default value
|
|
85
|
+
name.reset()
|
|
86
|
+
print(name.value) # ""
|
|
87
|
+
|
|
88
|
+
### Null checking
|
|
89
|
+
balance = Float(None)
|
|
90
|
+
print(balance.is_null()) # True
|
|
91
|
+
|
|
92
|
+
## License
|
|
93
|
+
MIT License
|
py_prim-0.1.0/README.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# py-prim
|
|
2
|
+
A robust, validated, and state-aware base class architecture for standard Python primitive data types.
|
|
3
|
+
|
|
4
|
+
In standard Python, primitives like int and str are loose and allow for silent state changes or type mixing. This package provides wrapper classes (Integer, String, etc.) that enforce strict type validation, provide standardized empty/null checks, and offer a consistent API across all basic data types.
|
|
5
|
+
|
|
6
|
+
## Features
|
|
7
|
+
Strict Type Validation: Fails fast if you try to assign a string to an integer, or mix up booleans and ints.
|
|
8
|
+
|
|
9
|
+
Standardized API: Every type implements .is_empty(), .is_null(), and .reset().
|
|
10
|
+
|
|
11
|
+
Magic Methods Support: Compares cleanly with standard Python types using == and integrates seamlessly with if statements.
|
|
12
|
+
|
|
13
|
+
Zero Dependencies: Built entirely on the Python standard library.
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
You can install this package directly from GitHub using either pip or uv.
|
|
17
|
+
|
|
18
|
+
Using pip:
|
|
19
|
+
|
|
20
|
+
pip install git+[https://github.com/saliktariq/Py-Prim.git](https://github.com/saliktariq/Py-Prim.git)
|
|
21
|
+
|
|
22
|
+
Using uv:
|
|
23
|
+
|
|
24
|
+
uv pip install git+[https://github.com/saliktariq/Py-Prim.git](https://github.com/saliktariq/Py-Prim.git)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
## Available Types
|
|
28
|
+
All types inherit from the Primitive abstract base class:
|
|
29
|
+
|
|
30
|
+
- Integer
|
|
31
|
+
- Float
|
|
32
|
+
- String
|
|
33
|
+
- Boolean
|
|
34
|
+
- Bytes
|
|
35
|
+
|
|
36
|
+
## Usage:
|
|
37
|
+
|
|
38
|
+
Access and mutate the underlying data using the .value property.
|
|
39
|
+
|
|
40
|
+
from primitives import Integer, String
|
|
41
|
+
|
|
42
|
+
### Initialize with a value
|
|
43
|
+
age = Integer(25)
|
|
44
|
+
print(age.value) # 25
|
|
45
|
+
|
|
46
|
+
### Change the value
|
|
47
|
+
age.value = 26
|
|
48
|
+
Strict Type Validation
|
|
49
|
+
The classes automatically validate types upon initialization and assignment, preventing accidental type mixing.
|
|
50
|
+
|
|
51
|
+
from primitives import Integer
|
|
52
|
+
|
|
53
|
+
score = Integer(100)
|
|
54
|
+
|
|
55
|
+
#### This will raise a ValueError: "Invalid value for Integer: 100.5"
|
|
56
|
+
score.value = 100.5
|
|
57
|
+
|
|
58
|
+
### This library strictly isolates Booleans from Integers.
|
|
59
|
+
score.value = True # Raises ValueError
|
|
60
|
+
State Checks and Resets
|
|
61
|
+
Every type knows what its "empty" and "default" states are.
|
|
62
|
+
|
|
63
|
+
from primitives import String, Float
|
|
64
|
+
|
|
65
|
+
name = String("")
|
|
66
|
+
print(name.is_empty()) # True
|
|
67
|
+
|
|
68
|
+
name.value = "Alice"
|
|
69
|
+
print(name.is_empty()) # False
|
|
70
|
+
|
|
71
|
+
### Reset back to the type's default value
|
|
72
|
+
name.reset()
|
|
73
|
+
print(name.value) # ""
|
|
74
|
+
|
|
75
|
+
### Null checking
|
|
76
|
+
balance = Float(None)
|
|
77
|
+
print(balance.is_null()) # True
|
|
78
|
+
|
|
79
|
+
## License
|
|
80
|
+
MIT License
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "py-prim"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Enhanced and validated base primitive data types for Python."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
authors = [{ name="Salik Tariq" }]
|
|
11
|
+
requires-python = ">=3.7"
|
|
12
|
+
classifiers = [
|
|
13
|
+
"Programming Language :: Python :: 3",
|
|
14
|
+
"License :: OSI Approved :: MIT License",
|
|
15
|
+
"Operating System :: OS Independent",
|
|
16
|
+
]
|
py_prim-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
from abc import ABC, abstractmethod
|
|
2
|
+
from typing import Any
|
|
3
|
+
|
|
4
|
+
class Primitive(ABC):
|
|
5
|
+
def __init__(self, value: Any = None):
|
|
6
|
+
self._value = value
|
|
7
|
+
# Run initial validation if a value is provided
|
|
8
|
+
if value is not None:
|
|
9
|
+
self.validate()
|
|
10
|
+
|
|
11
|
+
@property
|
|
12
|
+
def value(self) -> Any:
|
|
13
|
+
return self._value
|
|
14
|
+
|
|
15
|
+
@value.setter
|
|
16
|
+
def value(self, new_value: Any):
|
|
17
|
+
self._value = new_value
|
|
18
|
+
self.validate()
|
|
19
|
+
|
|
20
|
+
# --- Abstract Methods (Must be overridden) ---
|
|
21
|
+
|
|
22
|
+
@abstractmethod
|
|
23
|
+
def default_value(self) -> Any:
|
|
24
|
+
"""Return the default value for the type."""
|
|
25
|
+
pass
|
|
26
|
+
|
|
27
|
+
@abstractmethod
|
|
28
|
+
def is_empty(self) -> bool:
|
|
29
|
+
"""Determine if the value is functionally empty."""
|
|
30
|
+
pass
|
|
31
|
+
|
|
32
|
+
@abstractmethod
|
|
33
|
+
def is_valid(self) -> bool:
|
|
34
|
+
"""Return True if the value meets all type constraints."""
|
|
35
|
+
pass
|
|
36
|
+
|
|
37
|
+
# --- Generic Methods (Inherited by all) ---
|
|
38
|
+
|
|
39
|
+
def is_null(self) -> bool:
|
|
40
|
+
return self._value is None
|
|
41
|
+
|
|
42
|
+
def validate(self) -> None:
|
|
43
|
+
if not self.is_null() and not self.is_valid():
|
|
44
|
+
raise ValueError(f"Invalid value for {self.__class__.__name__}: {self._value}")
|
|
45
|
+
|
|
46
|
+
def reset(self) -> None:
|
|
47
|
+
self.value = self.default_value()
|
|
48
|
+
|
|
49
|
+
# --- Python Magic Methods ---
|
|
50
|
+
|
|
51
|
+
def __str__(self) -> str:
|
|
52
|
+
return str(self.default_value() if self.is_null() else self._value)
|
|
53
|
+
|
|
54
|
+
def __eq__(self, other: Any) -> bool:
|
|
55
|
+
# Allow comparison with raw primitive types or other Enhanced primitives
|
|
56
|
+
if isinstance(other, Primitive):
|
|
57
|
+
return self._value == other.value
|
|
58
|
+
return self._value == other
|
|
59
|
+
|
|
60
|
+
def __bool__(self) -> bool:
|
|
61
|
+
return not self.is_empty() and not self.is_null()
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
# ==========================================
|
|
65
|
+
# Derived Classes
|
|
66
|
+
# ==========================================
|
|
67
|
+
|
|
68
|
+
class Integer(Primitive):
|
|
69
|
+
def default_value(self) -> int:
|
|
70
|
+
return 0
|
|
71
|
+
|
|
72
|
+
def is_empty(self) -> bool:
|
|
73
|
+
return self._value == 0
|
|
74
|
+
|
|
75
|
+
def is_valid(self) -> bool:
|
|
76
|
+
# Explicitly exclude booleans since bool is a subclass of int in Python
|
|
77
|
+
return isinstance(self._value, int) and not isinstance(self._value, bool)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
class Float(Primitive):
|
|
81
|
+
def default_value(self) -> float:
|
|
82
|
+
return 0.0
|
|
83
|
+
|
|
84
|
+
def is_empty(self) -> bool:
|
|
85
|
+
return self._value == 0.0
|
|
86
|
+
|
|
87
|
+
def is_valid(self) -> bool:
|
|
88
|
+
return isinstance(self._value, (float, int)) and not isinstance(self._value, bool)
|
|
89
|
+
|
|
90
|
+
# Optional override: ensure the value is always stored as a float internally
|
|
91
|
+
@Primitive.value.setter
|
|
92
|
+
def value(self, new_value):
|
|
93
|
+
if isinstance(new_value, int) and not isinstance(new_value, bool):
|
|
94
|
+
new_value = float(new_value)
|
|
95
|
+
super(Float, type(self)).value.fset(self, new_value)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
class String(Primitive):
|
|
99
|
+
def default_value(self) -> str:
|
|
100
|
+
return ""
|
|
101
|
+
|
|
102
|
+
def is_empty(self) -> bool:
|
|
103
|
+
# Empty if it is length 0 or contains only whitespace
|
|
104
|
+
return self._value == "" or str(self._value).isspace()
|
|
105
|
+
|
|
106
|
+
def is_valid(self) -> bool:
|
|
107
|
+
return isinstance(self._value, str)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
class Boolean(Primitive):
|
|
111
|
+
def default_value(self) -> bool:
|
|
112
|
+
return False
|
|
113
|
+
|
|
114
|
+
def is_empty(self) -> bool:
|
|
115
|
+
return self._value is False
|
|
116
|
+
|
|
117
|
+
def is_valid(self) -> bool:
|
|
118
|
+
return isinstance(self._value, bool)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
class Bytes(Primitive):
|
|
122
|
+
def default_value(self) -> bytes:
|
|
123
|
+
return b""
|
|
124
|
+
|
|
125
|
+
def is_empty(self) -> bool:
|
|
126
|
+
return self._value == b""
|
|
127
|
+
|
|
128
|
+
def is_valid(self) -> bool:
|
|
129
|
+
return isinstance(self._value, bytes)
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: py-prim
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Enhanced and validated base primitive data types for Python.
|
|
5
|
+
Author: Salik Tariq
|
|
6
|
+
Classifier: Programming Language :: Python :: 3
|
|
7
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
8
|
+
Classifier: Operating System :: OS Independent
|
|
9
|
+
Requires-Python: >=3.7
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Dynamic: license-file
|
|
13
|
+
|
|
14
|
+
# py-prim
|
|
15
|
+
A robust, validated, and state-aware base class architecture for standard Python primitive data types.
|
|
16
|
+
|
|
17
|
+
In standard Python, primitives like int and str are loose and allow for silent state changes or type mixing. This package provides wrapper classes (Integer, String, etc.) that enforce strict type validation, provide standardized empty/null checks, and offer a consistent API across all basic data types.
|
|
18
|
+
|
|
19
|
+
## Features
|
|
20
|
+
Strict Type Validation: Fails fast if you try to assign a string to an integer, or mix up booleans and ints.
|
|
21
|
+
|
|
22
|
+
Standardized API: Every type implements .is_empty(), .is_null(), and .reset().
|
|
23
|
+
|
|
24
|
+
Magic Methods Support: Compares cleanly with standard Python types using == and integrates seamlessly with if statements.
|
|
25
|
+
|
|
26
|
+
Zero Dependencies: Built entirely on the Python standard library.
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
You can install this package directly from GitHub using either pip or uv.
|
|
30
|
+
|
|
31
|
+
Using pip:
|
|
32
|
+
|
|
33
|
+
pip install git+[https://github.com/saliktariq/Py-Prim.git](https://github.com/saliktariq/Py-Prim.git)
|
|
34
|
+
|
|
35
|
+
Using uv:
|
|
36
|
+
|
|
37
|
+
uv pip install git+[https://github.com/saliktariq/Py-Prim.git](https://github.com/saliktariq/Py-Prim.git)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
## Available Types
|
|
41
|
+
All types inherit from the Primitive abstract base class:
|
|
42
|
+
|
|
43
|
+
- Integer
|
|
44
|
+
- Float
|
|
45
|
+
- String
|
|
46
|
+
- Boolean
|
|
47
|
+
- Bytes
|
|
48
|
+
|
|
49
|
+
## Usage:
|
|
50
|
+
|
|
51
|
+
Access and mutate the underlying data using the .value property.
|
|
52
|
+
|
|
53
|
+
from primitives import Integer, String
|
|
54
|
+
|
|
55
|
+
### Initialize with a value
|
|
56
|
+
age = Integer(25)
|
|
57
|
+
print(age.value) # 25
|
|
58
|
+
|
|
59
|
+
### Change the value
|
|
60
|
+
age.value = 26
|
|
61
|
+
Strict Type Validation
|
|
62
|
+
The classes automatically validate types upon initialization and assignment, preventing accidental type mixing.
|
|
63
|
+
|
|
64
|
+
from primitives import Integer
|
|
65
|
+
|
|
66
|
+
score = Integer(100)
|
|
67
|
+
|
|
68
|
+
#### This will raise a ValueError: "Invalid value for Integer: 100.5"
|
|
69
|
+
score.value = 100.5
|
|
70
|
+
|
|
71
|
+
### This library strictly isolates Booleans from Integers.
|
|
72
|
+
score.value = True # Raises ValueError
|
|
73
|
+
State Checks and Resets
|
|
74
|
+
Every type knows what its "empty" and "default" states are.
|
|
75
|
+
|
|
76
|
+
from primitives import String, Float
|
|
77
|
+
|
|
78
|
+
name = String("")
|
|
79
|
+
print(name.is_empty()) # True
|
|
80
|
+
|
|
81
|
+
name.value = "Alice"
|
|
82
|
+
print(name.is_empty()) # False
|
|
83
|
+
|
|
84
|
+
### Reset back to the type's default value
|
|
85
|
+
name.reset()
|
|
86
|
+
print(name.value) # ""
|
|
87
|
+
|
|
88
|
+
### Null checking
|
|
89
|
+
balance = Float(None)
|
|
90
|
+
print(balance.is_null()) # True
|
|
91
|
+
|
|
92
|
+
## License
|
|
93
|
+
MIT License
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
primitives
|