pythonic-fp-booleans 1.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.
- pythonic_fp_booleans-1.1.0/.gitignore +7 -0
- pythonic_fp_booleans-1.1.0/CHANGELOG.rst +39 -0
- pythonic_fp_booleans-1.1.0/LICENSE +176 -0
- pythonic_fp_booleans-1.1.0/PKG-INFO +54 -0
- pythonic_fp_booleans-1.1.0/README.rst +28 -0
- pythonic_fp_booleans-1.1.0/pyproject.toml +79 -0
- pythonic_fp_booleans-1.1.0/src/pythonic_fp/booleans/__init__.py +99 -0
- pythonic_fp_booleans-1.1.0/src/pythonic_fp/booleans/py.typed +0 -0
- pythonic_fp_booleans-1.1.0/src/pythonic_fp/booleans/subtypable.py +143 -0
- pythonic_fp_booleans-1.1.0/src/pythonic_fp/booleans/subtypable.pyi +18 -0
- pythonic_fp_booleans-1.1.0/src/pythonic_fp/booleans/subtypes/__init__.py +37 -0
- pythonic_fp_booleans-1.1.0/src/pythonic_fp/booleans/subtypes/flavored.py +143 -0
- pythonic_fp_booleans-1.1.0/src/pythonic_fp/booleans/subtypes/flavored.pyi +19 -0
- pythonic_fp_booleans-1.1.0/src/pythonic_fp/booleans/subtypes/truthy_falsy.py +160 -0
- pythonic_fp_booleans-1.1.0/src/pythonic_fp/booleans/subtypes/truthy_falsy.pyi +21 -0
- pythonic_fp_booleans-1.1.0/tests/test_bool_vs_fbool.py +195 -0
- pythonic_fp_booleans-1.1.0/tests/test_bool_vs_sbool.py +160 -0
- pythonic_fp_booleans-1.1.0/tests/test_flavored.py +167 -0
- pythonic_fp_booleans-1.1.0/tests/test_flavored_non_shortcut_logic.py +112 -0
- pythonic_fp_booleans-1.1.0/tests/test_flavored_sbool.py +162 -0
- pythonic_fp_booleans-1.1.0/tests/test_subtypable_non_shortcut_logic.py +83 -0
- pythonic_fp_booleans-1.1.0/tests/test_true_false.py +189 -0
- pythonic_fp_booleans-1.1.0/tests/test_true_false_non_shortcut_logic.py +157 -0
- pythonic_fp_booleans-1.1.0/tests/test_typing.py +98 -0
- pythonic_fp_booleans-1.1.0/tests/test_variance.py +187 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
CHANGELOG
|
|
2
|
+
=========
|
|
3
|
+
|
|
4
|
+
PyPI pythonic-fp-booleans project.
|
|
5
|
+
|
|
6
|
+
Semantic Versioning
|
|
7
|
+
-------------------
|
|
8
|
+
|
|
9
|
+
Strict 3 digit semantic versioning adopted 2025-05-19.
|
|
10
|
+
|
|
11
|
+
- **MAJOR** version incremented for incompatible API changes
|
|
12
|
+
- **MINOR** version incremented for backward compatible added functionality
|
|
13
|
+
- **PATCH** version incremented for backward compatible bug fixes
|
|
14
|
+
|
|
15
|
+
See `Semantic Versioning 2.0.0 <https://semver.org>`_.
|
|
16
|
+
|
|
17
|
+
Releases and Important Milestones
|
|
18
|
+
---------------------------------
|
|
19
|
+
|
|
20
|
+
PyPI v1.1.0 - 2025-09-02
|
|
21
|
+
~~~~~~~~~~~~~~~~~~~~~~~~
|
|
22
|
+
|
|
23
|
+
First PyPI release.
|
|
24
|
+
|
|
25
|
+
- module booleans.subtypable
|
|
26
|
+
- package booleans.subtypes
|
|
27
|
+
|
|
28
|
+
- module booleans.subtypes.flavored
|
|
29
|
+
- module booleans.subtypes.truthy_falsy
|
|
30
|
+
|
|
31
|
+
Needs
|
|
32
|
+
|
|
33
|
+
- "pythonic-fp>=3.0.0" for gadgets
|
|
34
|
+
- "pythonic-fp-sentinels>=2.1.0",
|
|
35
|
+
|
|
36
|
+
Created pythonic-fp-boolean GitHub repo - 2025-08-06
|
|
37
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
38
|
+
|
|
39
|
+
Moved pythonic_fp.singletons.sbool -> pythonic_fp.booleans.sbool
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pythonic-fp-booleans
|
|
3
|
+
Version: 1.1.0
|
|
4
|
+
Summary: Subtypable Boolean like classes
|
|
5
|
+
Keywords: boolean,inheritable
|
|
6
|
+
Author-email: "Geoffrey R. Scheller" <geoffrey@scheller.com>
|
|
7
|
+
Requires-Python: >=3.13
|
|
8
|
+
Description-Content-Type: text/x-rst
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Framework :: Pytest
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
+
Classifier: Typing :: Typed
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Requires-Dist: pythonic-fp-gadgets>=3.0.0
|
|
18
|
+
Requires-Dist: pythonic-fp-sentinels>=2.1.0
|
|
19
|
+
Requires-Dist: pytest>=8.4.1 ; extra == "test"
|
|
20
|
+
Project-URL: Changelog, https://github.com/grscheller/pythonic-fp-booleans/blob/main/CHANGELOG.rst
|
|
21
|
+
Project-URL: Documentation, https://grscheller.github.io/pythonic-fp/booleans/development/build/html/releases.html
|
|
22
|
+
Project-URL: Homepage, https://github.com/grscheller/pythonic-fp/blob/main/README.md
|
|
23
|
+
Project-URL: Source, https://github.com/grscheller/pythonic-fp-booleans
|
|
24
|
+
Provides-Extra: test
|
|
25
|
+
|
|
26
|
+
Pythonic FP - Booleans
|
|
27
|
+
======================
|
|
28
|
+
|
|
29
|
+
PyPI project
|
|
30
|
+
`pythonic-fp-booleans
|
|
31
|
+
<https://pypi.org/project/pythonic-fp-booleans>`_.
|
|
32
|
+
|
|
33
|
+
Library of simple, but useful, data structures with minimal dependencies.
|
|
34
|
+
|
|
35
|
+
- single item box
|
|
36
|
+
- function returning iterator of its arguments
|
|
37
|
+
|
|
38
|
+
This PyPI project is part of of the grscheller
|
|
39
|
+
`pythonic-fp namespace projects
|
|
40
|
+
<https://github.com/grscheller/pythonic-fp/blob/main/README.md>`_
|
|
41
|
+
|
|
42
|
+
Documentation
|
|
43
|
+
-------------
|
|
44
|
+
|
|
45
|
+
Documentation for this project is hosted on
|
|
46
|
+
`GitHub Pages
|
|
47
|
+
<https://grscheller.github.io/pythonic-fp/gadgets/development/build/html>`_.
|
|
48
|
+
|
|
49
|
+
Copyright and License
|
|
50
|
+
---------------------
|
|
51
|
+
|
|
52
|
+
Copyright (c) 2025 Geoffrey R. Scheller. Licensed under the Apache
|
|
53
|
+
License, Version 2.0. See the LICENSE file for details.
|
|
54
|
+
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Pythonic FP - Booleans
|
|
2
|
+
======================
|
|
3
|
+
|
|
4
|
+
PyPI project
|
|
5
|
+
`pythonic-fp-booleans
|
|
6
|
+
<https://pypi.org/project/pythonic-fp-booleans>`_.
|
|
7
|
+
|
|
8
|
+
Library of simple, but useful, data structures with minimal dependencies.
|
|
9
|
+
|
|
10
|
+
- single item box
|
|
11
|
+
- function returning iterator of its arguments
|
|
12
|
+
|
|
13
|
+
This PyPI project is part of of the grscheller
|
|
14
|
+
`pythonic-fp namespace projects
|
|
15
|
+
<https://github.com/grscheller/pythonic-fp/blob/main/README.md>`_
|
|
16
|
+
|
|
17
|
+
Documentation
|
|
18
|
+
-------------
|
|
19
|
+
|
|
20
|
+
Documentation for this project is hosted on
|
|
21
|
+
`GitHub Pages
|
|
22
|
+
<https://grscheller.github.io/pythonic-fp/gadgets/development/build/html>`_.
|
|
23
|
+
|
|
24
|
+
Copyright and License
|
|
25
|
+
---------------------
|
|
26
|
+
|
|
27
|
+
Copyright (c) 2025 Geoffrey R. Scheller. Licensed under the Apache
|
|
28
|
+
License, Version 2.0. See the LICENSE file for details.
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "pythonic-fp-booleans"
|
|
3
|
+
version = "1.1.0"
|
|
4
|
+
readme = "README.rst"
|
|
5
|
+
requires-python = ">=3.13"
|
|
6
|
+
license = { file = "LICENSE" }
|
|
7
|
+
authors = [{ name = "Geoffrey R. Scheller", email = "geoffrey@scheller.com" }]
|
|
8
|
+
keywords = [
|
|
9
|
+
"boolean",
|
|
10
|
+
"inheritable",
|
|
11
|
+
]
|
|
12
|
+
classifiers = [
|
|
13
|
+
"Development Status :: 3 - Alpha",
|
|
14
|
+
"Framework :: Pytest",
|
|
15
|
+
"Intended Audience :: Developers",
|
|
16
|
+
"License :: OSI Approved :: Apache Software License",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
"Programming Language :: Python :: 3.13",
|
|
19
|
+
"Typing :: Typed",
|
|
20
|
+
]
|
|
21
|
+
dependencies = [
|
|
22
|
+
"pythonic-fp-gadgets>=3.0.0",
|
|
23
|
+
"pythonic-fp-sentinels>=2.1.0",
|
|
24
|
+
]
|
|
25
|
+
dynamic = ["description"]
|
|
26
|
+
|
|
27
|
+
[project.urls]
|
|
28
|
+
Changelog = "https://github.com/grscheller/pythonic-fp-booleans/blob/main/CHANGELOG.rst"
|
|
29
|
+
Documentation = "https://grscheller.github.io/pythonic-fp/booleans/development/build/html/releases.html"
|
|
30
|
+
Homepage = "https://github.com/grscheller/pythonic-fp/blob/main/README.md"
|
|
31
|
+
Source = "https://github.com/grscheller/pythonic-fp-booleans"
|
|
32
|
+
|
|
33
|
+
[project.optional-dependencies]
|
|
34
|
+
test = [
|
|
35
|
+
"pytest>=8.4.1",
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
[build-system]
|
|
39
|
+
requires = ["flit_core>=3.12,<4"]
|
|
40
|
+
build-backend = "flit_core.buildapi"
|
|
41
|
+
|
|
42
|
+
[tool.flit.module]
|
|
43
|
+
name = "pythonic_fp.booleans"
|
|
44
|
+
|
|
45
|
+
[tool.mypy]
|
|
46
|
+
enable_incomplete_feature = "NewGenericSyntax"
|
|
47
|
+
explicit_package_bases = true
|
|
48
|
+
implicit_reexport = false
|
|
49
|
+
local_partial_types = true
|
|
50
|
+
namespace_packages = true
|
|
51
|
+
warn_redundant_casts = true
|
|
52
|
+
warn_return_any = true
|
|
53
|
+
warn_unused_configs = true
|
|
54
|
+
|
|
55
|
+
[tool.pylsp-mypy]
|
|
56
|
+
enabled = true
|
|
57
|
+
live-mode = true
|
|
58
|
+
dmypy = false
|
|
59
|
+
strict = true
|
|
60
|
+
report_progress = true
|
|
61
|
+
|
|
62
|
+
[tool.pytest.ini_options]
|
|
63
|
+
addopts = "-ra"
|
|
64
|
+
consider_namespace_packages = true
|
|
65
|
+
testpaths = ["tests/"]
|
|
66
|
+
|
|
67
|
+
[tool.ruff]
|
|
68
|
+
target-version = "py313"
|
|
69
|
+
|
|
70
|
+
[tool.ruff.lint.flake8-quotes]
|
|
71
|
+
docstring-quotes = "double"
|
|
72
|
+
|
|
73
|
+
[tool.ruff.lint.per-file-ignores]
|
|
74
|
+
"tests/*" = ["C901"]
|
|
75
|
+
"**/*.py" = ["E741"]
|
|
76
|
+
|
|
77
|
+
[tool.ruff.format]
|
|
78
|
+
quote-style = "single"
|
|
79
|
+
docstring-code-line-length = 72
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# Copyright 2023-2025 Geoffrey R. Scheller
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
"""
|
|
16
|
+
Subtypable Boolean like classes
|
|
17
|
+
===============================
|
|
18
|
+
|
|
19
|
+
While still compatible with Python shortcut logic, these classes can
|
|
20
|
+
be non-shortcut logically composed with Python's bitwise operators.
|
|
21
|
+
These classes are implemented with the Singleton Pattern.
|
|
22
|
+
|
|
23
|
+
Covariant class hierarchy
|
|
24
|
+
-------------------------
|
|
25
|
+
|
|
26
|
+
.. graphviz::
|
|
27
|
+
|
|
28
|
+
digraph Booleans {
|
|
29
|
+
bgcolor="deepskyblue";
|
|
30
|
+
int -> bool;
|
|
31
|
+
int -> SBool;
|
|
32
|
+
SBool -> "FBool(h1)";
|
|
33
|
+
SBool -> "FBool(h2)";
|
|
34
|
+
SBool -> "FBool(h3)";
|
|
35
|
+
SBool -> TF_Bool;
|
|
36
|
+
TF_Bool -> T_Bool;
|
|
37
|
+
TF_Bool -> F_Bool;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
Contravariant non-shortcut "bitwise" operators
|
|
41
|
+
----------------------------------------------
|
|
42
|
+
|
|
43
|
+
+-------------------+--------+------------+
|
|
44
|
+
| Boolean operation | symbol | dunder |
|
|
45
|
+
+===================+========+============+
|
|
46
|
+
| not | ``~`` | __invert__ |
|
|
47
|
+
+-------------------+--------+------------+
|
|
48
|
+
| and | ``&`` | __and__ |
|
|
49
|
+
+-------------------+--------+------------+
|
|
50
|
+
| or | ``|`` | __or__ |
|
|
51
|
+
+-------------------+--------+------------+
|
|
52
|
+
| xor | ``^`` | __xor__ |
|
|
53
|
+
+-------------------+--------+------------+
|
|
54
|
+
|
|
55
|
+
These operators are contravariant, that is they will return
|
|
56
|
+
the instance of the latest common ancestor of their arguments.
|
|
57
|
+
More specifically, the instance returned will have the type
|
|
58
|
+
of the least upper bound in the inheritance graph of the classes
|
|
59
|
+
of the two arguments.
|
|
60
|
+
|
|
61
|
+
.. warning::
|
|
62
|
+
|
|
63
|
+
These "bitwise" operators could raise ``TypeError`` exceptions
|
|
64
|
+
when applied against an ``SBool`` and objects not descended
|
|
65
|
+
from ``int``.
|
|
66
|
+
|
|
67
|
+
Classes
|
|
68
|
+
-------
|
|
69
|
+
|
|
70
|
+
Class SBool
|
|
71
|
+
~~~~~~~~~~~
|
|
72
|
+
|
|
73
|
+
Base of the hierarchy.
|
|
74
|
+
|
|
75
|
+
Like Python's built-in ``bool``, ``SBool`` is a subclass of ``int``,
|
|
76
|
+
unlike ``bool``, class ``SBool`` can be further subclassed.
|
|
77
|
+
|
|
78
|
+
Class FBool
|
|
79
|
+
~~~~~~~~~~~
|
|
80
|
+
|
|
81
|
+
For when you need to deal with different "flavors" of the truth.
|
|
82
|
+
|
|
83
|
+
Each "flavor" corresponds to a hashable value. Instances of ``FBool``
|
|
84
|
+
are invariant in their flavor. Best to think of the "flavor" as an
|
|
85
|
+
index.
|
|
86
|
+
|
|
87
|
+
Class TF_Bool
|
|
88
|
+
~~~~~~~~~~~~~
|
|
89
|
+
|
|
90
|
+
Class ``TF_Bool`` consists of just two disjoint subclasses, each one
|
|
91
|
+
a singleton.
|
|
92
|
+
|
|
93
|
+
- class ``T_Bool`` is the always truthy ``TF_Bool`` subtype
|
|
94
|
+
- class ``F_Bool`` is the always falsy ``TF_Bool`` subtype
|
|
95
|
+
"""
|
|
96
|
+
|
|
97
|
+
__author__ = 'Geoffrey R. Scheller'
|
|
98
|
+
__copyright__ = 'Copyright (c) 2025 Geoffrey R. Scheller'
|
|
99
|
+
__license__ = 'Apache License 2.0'
|
|
File without changes
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# Copyright 2023-2025 Geoffrey R. Scheller
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
"""Subtypable Booleans."""
|
|
17
|
+
|
|
18
|
+
import threading
|
|
19
|
+
from collections.abc import Hashable
|
|
20
|
+
from typing import cast, ClassVar, Final, overload
|
|
21
|
+
from pythonic_fp.gadgets.latest_common_ancestor import lca
|
|
22
|
+
from pythonic_fp.sentinels.novalue import NoValue
|
|
23
|
+
|
|
24
|
+
__all__ = ['SBool', 'TRUTH', 'LIE']
|
|
25
|
+
|
|
26
|
+
_novalue = NoValue()
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class SBool(int):
|
|
30
|
+
"""Subtypable Booleans.
|
|
31
|
+
|
|
32
|
+
Like Python's built in bool, class SBool is a subclass of int.
|
|
33
|
+
Unlike bool, this version can be further subclassed. It can be
|
|
34
|
+
used with Python ``and`` and ``or`` short-cut logic. The ``not``
|
|
35
|
+
operator will just return a ``bool``. Use the ``snot`` function
|
|
36
|
+
to return an ``SBool`` or ``SBool`` subclass.
|
|
37
|
+
|
|
38
|
+
This type and its subtypes can also do (non-shortcut) Boolean logic
|
|
39
|
+
using Python bitwise operators.
|
|
40
|
+
"""
|
|
41
|
+
_falsy: 'ClassVar[SBool | NoValue]' = _novalue
|
|
42
|
+
_falsy_lock: ClassVar[threading.Lock] = threading.Lock()
|
|
43
|
+
|
|
44
|
+
_truthy: 'ClassVar[SBool | NoValue]' = _novalue
|
|
45
|
+
_truthy_lock: ClassVar[threading.Lock] = threading.Lock()
|
|
46
|
+
|
|
47
|
+
@overload
|
|
48
|
+
def __new__(cls) -> 'SBool': ...
|
|
49
|
+
@overload
|
|
50
|
+
def __new__(cls, witness: object) -> 'SBool': ...
|
|
51
|
+
|
|
52
|
+
def __new__(cls, witness: object = False, flavor: Hashable = _novalue) -> 'SBool':
|
|
53
|
+
"""
|
|
54
|
+
:param witness: Determines truthiness of the ``SBool``.
|
|
55
|
+
:returns: The truthy or falsy SBool class instance.
|
|
56
|
+
"""
|
|
57
|
+
if witness:
|
|
58
|
+
if cls._truthy is _novalue:
|
|
59
|
+
with cls._truthy_lock:
|
|
60
|
+
if cls._truthy is _novalue:
|
|
61
|
+
cls._truthy = super().__new__(cls, 1)
|
|
62
|
+
return cast(SBool, cls._truthy)
|
|
63
|
+
else:
|
|
64
|
+
if cls._falsy is _novalue:
|
|
65
|
+
with cls._falsy_lock:
|
|
66
|
+
if cls._falsy is _novalue:
|
|
67
|
+
cls._falsy = super().__new__(cls, 0)
|
|
68
|
+
return cast(SBool, cls._falsy)
|
|
69
|
+
|
|
70
|
+
def __init__(self, witness: object = False, flavor: Hashable = _novalue) -> None:
|
|
71
|
+
self._flavor = flavor
|
|
72
|
+
|
|
73
|
+
# override in derived classes
|
|
74
|
+
def __repr__(self) -> str:
|
|
75
|
+
if self:
|
|
76
|
+
return 'TRUTH'
|
|
77
|
+
return 'LIE'
|
|
78
|
+
|
|
79
|
+
def __invert__(self) -> 'SBool':
|
|
80
|
+
if self:
|
|
81
|
+
return type(self)(False)
|
|
82
|
+
return type(self)(True)
|
|
83
|
+
|
|
84
|
+
def __and__(self, other: int) -> int:
|
|
85
|
+
try:
|
|
86
|
+
base_class = lca(type(self), type(other))
|
|
87
|
+
except TypeError:
|
|
88
|
+
if type(other) is bool:
|
|
89
|
+
base_class = int
|
|
90
|
+
else:
|
|
91
|
+
msg = (
|
|
92
|
+
f"unsupported operand type(s) for &: '{type(self)}' and '{type(other)}'"
|
|
93
|
+
)
|
|
94
|
+
raise TypeError(msg)
|
|
95
|
+
|
|
96
|
+
if issubclass(base_class, SBool):
|
|
97
|
+
if self and other:
|
|
98
|
+
return base_class(1)
|
|
99
|
+
return base_class(0)
|
|
100
|
+
else:
|
|
101
|
+
return int(self) & int(other)
|
|
102
|
+
|
|
103
|
+
def __or__(self, other: int) -> int:
|
|
104
|
+
try:
|
|
105
|
+
base_class = lca(type(self), type(other))
|
|
106
|
+
except TypeError:
|
|
107
|
+
if type(other) is bool:
|
|
108
|
+
base_class = int
|
|
109
|
+
else:
|
|
110
|
+
msg = (
|
|
111
|
+
f"unsupported operand type(s) for |: '{type(self)}' and '{type(other)}'"
|
|
112
|
+
)
|
|
113
|
+
raise TypeError(msg)
|
|
114
|
+
|
|
115
|
+
if issubclass(base_class, SBool):
|
|
116
|
+
if self or other:
|
|
117
|
+
return base_class(1)
|
|
118
|
+
return base_class(0)
|
|
119
|
+
else:
|
|
120
|
+
return int(self) | int(other)
|
|
121
|
+
|
|
122
|
+
def __xor__(self, other: int) -> int:
|
|
123
|
+
try:
|
|
124
|
+
base_class = lca(type(self), type(other))
|
|
125
|
+
except TypeError:
|
|
126
|
+
if type(other) is bool:
|
|
127
|
+
base_class = int
|
|
128
|
+
else:
|
|
129
|
+
msg = (
|
|
130
|
+
f"unsupported operand type(s) for ^: '{type(self)}' and '{type(other)}'"
|
|
131
|
+
)
|
|
132
|
+
raise TypeError(msg)
|
|
133
|
+
|
|
134
|
+
if issubclass(base_class, SBool):
|
|
135
|
+
if self and not other or other and not self:
|
|
136
|
+
return base_class(1)
|
|
137
|
+
return base_class(0)
|
|
138
|
+
else:
|
|
139
|
+
return int(self) ^ int(other)
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
TRUTH: Final[SBool] = SBool(True) #: The truthy singleton of type ``SBool``.
|
|
143
|
+
LIE: Final[SBool] = SBool(False) #: The falsy singleton of type ``SBool``.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from collections.abc import Hashable
|
|
2
|
+
from typing import Final, overload
|
|
3
|
+
|
|
4
|
+
__all__ = ['SBool', 'TRUTH', 'LIE']
|
|
5
|
+
|
|
6
|
+
class SBool(int):
|
|
7
|
+
@overload
|
|
8
|
+
def __new__(cls) -> SBool: ...
|
|
9
|
+
@overload
|
|
10
|
+
def __new__(cls, witness: object) -> SBool: ...
|
|
11
|
+
def __init__(self, witness: object = False, flavor: Hashable = ...) -> None: ...
|
|
12
|
+
def __invert__(self) -> SBool: ...
|
|
13
|
+
def __and__(self, other: int) -> int: ...
|
|
14
|
+
def __or__(self, other: int) -> int: ...
|
|
15
|
+
def __xor__(self, other: int) -> int: ...
|
|
16
|
+
|
|
17
|
+
TRUTH: Final[SBool]
|
|
18
|
+
LIE: Final[SBool]
|