pd-code-sanity 0.0.1__tar.gz → 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.
@@ -0,0 +1,42 @@
1
+ Metadata-Version: 2.4
2
+ Name: pd-code-sanity
3
+ Version: 0.1.0
4
+ Summary: check pd_code weak sanity.
5
+ License: MIT
6
+ License-File: LICENSE
7
+ Author: GGN_2015
8
+ Author-email: neko@jlulug.org
9
+ Requires-Python: >=3.10
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Programming Language :: Python :: 3.14
17
+ Description-Content-Type: text/markdown
18
+
19
+ # pd-code-sanity
20
+
21
+ Validate the structural invariants of planar-diagram codes.
22
+
23
+ ## Installation
24
+
25
+ ```bash
26
+ pip install pd-code-sanity
27
+ ```
28
+
29
+ ## Quick start
30
+
31
+ `from pd_code_sanity import sanity`; the function returns a boolean.
32
+
33
+ PD codes are lists of four-entry crossings. Each arc label must occur exactly twice. Functions validate their inputs and do not mutate caller-owned PD-code lists unless explicitly documented.
34
+
35
+ ## Development
36
+
37
+ Use Python 3.10 or newer for Python packages. Build distributions with `poetry build`. Run the package's tests or examples before publishing. C++ projects require a modern standards-compliant compiler.
38
+
39
+ ## License
40
+
41
+ MIT. See `LICENSE`.
42
+
@@ -0,0 +1,23 @@
1
+ # pd-code-sanity
2
+
3
+ Validate the structural invariants of planar-diagram codes.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pip install pd-code-sanity
9
+ ```
10
+
11
+ ## Quick start
12
+
13
+ `from pd_code_sanity import sanity`; the function returns a boolean.
14
+
15
+ PD codes are lists of four-entry crossings. Each arc label must occur exactly twice. Functions validate their inputs and do not mutate caller-owned PD-code lists unless explicitly documented.
16
+
17
+ ## Development
18
+
19
+ Use Python 3.10 or newer for Python packages. Build distributions with `poetry build`. Run the package's tests or examples before publishing. C++ projects require a modern standards-compliant compiler.
20
+
21
+ ## License
22
+
23
+ MIT. See `LICENSE`.
@@ -0,0 +1,28 @@
1
+ from collections import Counter
2
+ from typing import Any
3
+
4
+
5
+ def sanity(pd_code: list[list[int | str]]) -> bool:
6
+ """Return whether *pd_code* has the structural invariants of a PD code."""
7
+ if not isinstance(pd_code, list):
8
+ return False
9
+
10
+ labels: list[Any] = []
11
+ label_type: type | None = None
12
+ for crossing in pd_code:
13
+ if not isinstance(crossing, list) or len(crossing) != 4:
14
+ return False
15
+ for label in crossing:
16
+ if isinstance(label, bool) or not isinstance(label, (int, str)):
17
+ return False
18
+ if label_type is None:
19
+ label_type = type(label)
20
+ elif type(label) is not label_type:
21
+ return False
22
+ try:
23
+ hash(label)
24
+ except TypeError:
25
+ return False
26
+ labels.append(label)
27
+
28
+ return all(count == 2 for count in Counter(labels).values())
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "pd-code-sanity"
3
- version = "0.0.1"
3
+ version = "0.1.0"
4
4
  description = "check pd_code weak sanity."
5
5
  authors = [
6
6
  {name = "GGN_2015",email = "neko@jlulug.org"}
@@ -1,35 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: pd-code-sanity
3
- Version: 0.0.1
4
- Summary: check pd_code weak sanity.
5
- License: MIT
6
- License-File: LICENSE
7
- Author: GGN_2015
8
- Author-email: neko@jlulug.org
9
- Requires-Python: >=3.10
10
- Classifier: License :: OSI Approved :: MIT License
11
- Classifier: Programming Language :: Python :: 3
12
- Classifier: Programming Language :: Python :: 3.10
13
- Classifier: Programming Language :: Python :: 3.11
14
- Classifier: Programming Language :: Python :: 3.12
15
- Classifier: Programming Language :: Python :: 3.13
16
- Classifier: Programming Language :: Python :: 3.14
17
- Description-Content-Type: text/markdown
18
-
19
- # pd_code_sanity
20
- check pd_code weak sanity.
21
-
22
- ## Install
23
-
24
- ```bash
25
- pip install pd-code-sanity
26
- ```
27
-
28
- ## Usage
29
-
30
- ```python
31
- import pd_code_sanity
32
-
33
- print(pd_code_sanity.sanity([[1, 5, 2, 4], [3, 1, 4, 6], [5, 3, 6, 2]]))
34
- ```
35
-
@@ -1,16 +0,0 @@
1
- # pd_code_sanity
2
- check pd_code weak sanity.
3
-
4
- ## Install
5
-
6
- ```bash
7
- pip install pd-code-sanity
8
- ```
9
-
10
- ## Usage
11
-
12
- ```python
13
- import pd_code_sanity
14
-
15
- print(pd_code_sanity.sanity([[1, 5, 2, 4], [3, 1, 4, 6], [5, 3, 6, 2]]))
16
- ```
@@ -1,37 +0,0 @@
1
-
2
- # 检查 pd_code 的合法性
3
- def sanity(pd_code:list[list[int | str]]) -> bool:
4
- cnt = dict()
5
-
6
- # 检查外层对象类型
7
- if not isinstance(pd_code, list):
8
- return False
9
-
10
- # 检查内层对象
11
- for crossing in pd_code:
12
- if not isinstance(crossing, list):
13
- return False
14
-
15
- # 检查元素个数合法
16
- if len(crossing) != 4:
17
- return False
18
-
19
- # 检查元素类型合法
20
- for term in crossing:
21
-
22
- # 检查内层对象类型
23
- if ((not isinstance(term, str))
24
- and (not isinstance(term, int))):
25
- return False
26
-
27
- # 统计每个对象出现次数
28
- if cnt.get(term) is None:
29
- cnt[term] = 0
30
- cnt[term] += 1
31
-
32
- # 每个元素恰好出现两次
33
- for term in cnt:
34
- if cnt[term] != 2:
35
- return False
36
-
37
- return True
File without changes