Skip to content

Commit db0362a

Browse files
behdadclaude
andcommitted
Release version 1.0.0
- Fix mapping parameter to accept bidirectional mappings - Bump version from 0.4.0 to 1.0.0 - Update development status from Beta to Production/Stable Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
1 parent 147f98f commit db0362a

2 files changed

Lines changed: 31 additions & 6 deletions

File tree

packTab/__init__.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
"binaryBitsFor",
102102
]
103103

104-
__version__ = "0.4.0"
104+
__version__ = "1.0.0"
105105

106106

107107
class AutoMapping(collections.defaultdict):
@@ -1317,16 +1317,41 @@ def pack_table(
13171317

13181318
# Set up mapping. See docstring.
13191319
if mapping is not None:
1320-
# Validate mapping is consistently int→str or str→int
1320+
# Validate and normalize mapping to be bidirectional.
1321+
# Accept either unidirectional (all int→str or all str→int) or
1322+
# already-bidirectional mappings.
13211323
if not mapping:
13221324
raise ValueError("mapping must not be empty")
1325+
1326+
# Check if it's a valid unidirectional mapping
13231327
int_to_nonint = all(isinstance(k, int) and not isinstance(v, int) for k, v in mapping.items())
13241328
nonint_to_int = all(not isinstance(k, int) and isinstance(v, int) for k, v in mapping.items())
1329+
1330+
# Check if it's already bidirectional: every int key has a corresponding
1331+
# non-int value that maps back, and vice versa
13251332
if not (int_to_nonint or nonint_to_int):
1326-
raise TypeError("mapping must be consistently int→str or str→int, not mixed")
1333+
# Not unidirectional, check if it's a valid bidirectional mapping
1334+
int_keys = {k for k in mapping.keys() if isinstance(k, int)}
1335+
nonint_keys = {k for k in mapping.keys() if not isinstance(k, int)}
1336+
1337+
# Verify bidirectional consistency: for all int→nonint pairs,
1338+
# nonint→int must exist and match
1339+
is_bidirectional = (
1340+
int_keys and nonint_keys and
1341+
all(isinstance(mapping.get(k), int) for k in nonint_keys) and
1342+
all(not isinstance(mapping.get(k), int) for k in int_keys) and
1343+
all(mapping.get(mapping.get(k)) == k for k in int_keys) and
1344+
all(mapping.get(mapping.get(k)) == k for k in nonint_keys)
1345+
)
1346+
1347+
if not is_bidirectional:
1348+
raise TypeError("mapping must be consistently int→str or str→int, or a valid bidirectional mapping")
1349+
1350+
# Make bidirectional if not already
13271351
mapping2 = mapping.copy()
13281352
for k, v in mapping.items():
1329-
mapping2[v] = k
1353+
if v not in mapping2:
1354+
mapping2[v] = k
13301355
mapping = mapping2
13311356
del mapping2
13321357

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "packtab"
7-
version = "0.4.0"
7+
version = "1.0.0"
88
description = "Unicode (and other integer) table packer"
99
readme = "README.md"
1010
requires-python = ">=3.8"
@@ -13,7 +13,7 @@ authors = [
1313
{name = "Behdad Esfahbod", email = "[email protected]"}
1414
]
1515
classifiers = [
16-
"Development Status :: 4 - Beta",
16+
"Development Status :: 5 - Production/Stable",
1717
"Intended Audience :: Developers",
1818
"Operating System :: OS Independent",
1919
"Programming Language :: Python :: 3",

0 commit comments

Comments
 (0)