ucon 0.6.1__py3-none-any.whl → 0.6.2__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.
- ucon/units.py +18 -2
- {ucon-0.6.1.dist-info → ucon-0.6.2.dist-info}/METADATA +1 -1
- {ucon-0.6.1.dist-info → ucon-0.6.2.dist-info}/RECORD +8 -8
- {ucon-0.6.1.dist-info → ucon-0.6.2.dist-info}/WHEEL +0 -0
- {ucon-0.6.1.dist-info → ucon-0.6.2.dist-info}/entry_points.txt +0 -0
- {ucon-0.6.1.dist-info → ucon-0.6.2.dist-info}/licenses/LICENSE +0 -0
- {ucon-0.6.1.dist-info → ucon-0.6.2.dist-info}/licenses/NOTICE +0 -0
- {ucon-0.6.1.dist-info → ucon-0.6.2.dist-info}/top_level.txt +0 -0
ucon/units.py
CHANGED
|
@@ -204,6 +204,10 @@ def have(name: str) -> bool:
|
|
|
204
204
|
_UNIT_REGISTRY: Dict[str, Unit] = {}
|
|
205
205
|
_UNIT_REGISTRY_CASE_SENSITIVE: Dict[str, Unit] = {}
|
|
206
206
|
|
|
207
|
+
# Priority aliases that must match exactly before prefix decomposition.
|
|
208
|
+
# Prevents ambiguous parses like "min" -> milli-inch instead of minute.
|
|
209
|
+
_PRIORITY_ALIASES: set = {'min'}
|
|
210
|
+
|
|
207
211
|
# Scale prefix mapping (shorthand -> Scale)
|
|
208
212
|
# Sorted by length descending for greedy matching
|
|
209
213
|
_SCALE_PREFIXES: Dict[str, Scale] = {
|
|
@@ -294,7 +298,10 @@ def _lookup_factor(s: str) -> Tuple[Unit, Scale]:
|
|
|
294
298
|
"""
|
|
295
299
|
Look up a single unit factor, handling scale prefixes.
|
|
296
300
|
|
|
297
|
-
Prioritizes prefix+unit interpretation over direct unit lookup
|
|
301
|
+
Prioritizes prefix+unit interpretation over direct unit lookup,
|
|
302
|
+
except for priority aliases (like 'min') which are checked first
|
|
303
|
+
to avoid ambiguous parses.
|
|
304
|
+
|
|
298
305
|
This means "kg" returns (gram, Scale.kilo) rather than (kilogram, Scale.one).
|
|
299
306
|
|
|
300
307
|
Examples:
|
|
@@ -303,6 +310,7 @@ def _lookup_factor(s: str) -> Tuple[Unit, Scale]:
|
|
|
303
310
|
- 'km' -> (meter, Scale.kilo)
|
|
304
311
|
- 'kg' -> (gram, Scale.kilo)
|
|
305
312
|
- 'mL' -> (liter, Scale.milli)
|
|
313
|
+
- 'min' -> (minute, Scale.one) # priority alias, not milli-inch
|
|
306
314
|
|
|
307
315
|
Returns:
|
|
308
316
|
Tuple of (unit, scale).
|
|
@@ -310,7 +318,15 @@ def _lookup_factor(s: str) -> Tuple[Unit, Scale]:
|
|
|
310
318
|
Raises:
|
|
311
319
|
UnknownUnitError: If the unit cannot be resolved.
|
|
312
320
|
"""
|
|
313
|
-
#
|
|
321
|
+
# Check priority aliases first (prevents "min" -> milli-inch)
|
|
322
|
+
if s in _PRIORITY_ALIASES:
|
|
323
|
+
if s in _UNIT_REGISTRY_CASE_SENSITIVE:
|
|
324
|
+
return _UNIT_REGISTRY_CASE_SENSITIVE[s], Scale.one
|
|
325
|
+
s_lower = s.lower()
|
|
326
|
+
if s_lower in _UNIT_REGISTRY:
|
|
327
|
+
return _UNIT_REGISTRY[s_lower], Scale.one
|
|
328
|
+
|
|
329
|
+
# Try scale prefix + unit (prioritize decomposition)
|
|
314
330
|
# Only case-sensitive matching for remainder (e.g., "fT" = femto-tesla, "ft" = foot)
|
|
315
331
|
for prefix in _SCALE_PREFIXES_SORTED:
|
|
316
332
|
if s.startswith(prefix) and len(s) > len(prefix):
|
|
@@ -5,13 +5,13 @@ ucon/graph.py,sha256=vBIKwppYCAu5sw6R_3zTBlnOk2WmYMClIb6j5kDvJHI,21342
|
|
|
5
5
|
ucon/maps.py,sha256=-rPMOHylcQYUn62R9IU23bXdCRCRNBhdH3UD4G5IUEk,9123
|
|
6
6
|
ucon/pydantic.py,sha256=64ZR1EYFRnBGHj3VIF5pc3swdAiR2ZlYrgcntdbKN4k,5189
|
|
7
7
|
ucon/quantity.py,sha256=GBxZ_96nocx-8F-usNWGbPvWHRhRgdZzqfH9Sx69iC4,465
|
|
8
|
-
ucon/units.py,sha256=
|
|
8
|
+
ucon/units.py,sha256=3reuG-G-BAAOiH_es8CE5jxAFTg5bkrd2JQ5C1iBTFg,16676
|
|
9
9
|
ucon/mcp/__init__.py,sha256=WoFOQ7JeDIzbjjkFIJ0Uv53VVLu-4lrjzG5vpVGGfT4,123
|
|
10
10
|
ucon/mcp/server.py,sha256=uUrdevEaR65Qjh9xn8Q-_IusNjPGxdkLF9iQmiSTs0g,7016
|
|
11
|
-
ucon-0.6.
|
|
12
|
-
ucon-0.6.
|
|
13
|
-
ucon-0.6.
|
|
14
|
-
ucon-0.6.
|
|
15
|
-
ucon-0.6.
|
|
16
|
-
ucon-0.6.
|
|
17
|
-
ucon-0.6.
|
|
11
|
+
ucon-0.6.2.dist-info/licenses/LICENSE,sha256=LtimSYBSw1L_X6n1-VEdZRdwuROzPumrMUNX21asFuI,11356
|
|
12
|
+
ucon-0.6.2.dist-info/licenses/NOTICE,sha256=bh4fBOItio3kM4hSNYhqfFpcaAvOoixjD7Du8im-sYA,1079
|
|
13
|
+
ucon-0.6.2.dist-info/METADATA,sha256=5fBukT2t1v_OV17FdanlgFq6mFsKhXZuovhN6yJmg2s,17397
|
|
14
|
+
ucon-0.6.2.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
15
|
+
ucon-0.6.2.dist-info/entry_points.txt,sha256=jbfLf0FbOulgGa0nM_sRiTNfiCAkJcHnSSK_oj3g0cQ,50
|
|
16
|
+
ucon-0.6.2.dist-info/top_level.txt,sha256=Vv3KDuZ86fmH5yOYLbYap9DbBblK1YUkmlThffF71jA,5
|
|
17
|
+
ucon-0.6.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|