ucon 0.6.2__py3-none-any.whl → 0.6.3__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 +16 -3
- {ucon-0.6.2.dist-info → ucon-0.6.3.dist-info}/METADATA +1 -1
- {ucon-0.6.2.dist-info → ucon-0.6.3.dist-info}/RECORD +8 -8
- {ucon-0.6.2.dist-info → ucon-0.6.3.dist-info}/WHEEL +0 -0
- {ucon-0.6.2.dist-info → ucon-0.6.3.dist-info}/entry_points.txt +0 -0
- {ucon-0.6.2.dist-info → ucon-0.6.3.dist-info}/licenses/LICENSE +0 -0
- {ucon-0.6.2.dist-info → ucon-0.6.3.dist-info}/licenses/NOTICE +0 -0
- {ucon-0.6.2.dist-info → ucon-0.6.3.dist-info}/top_level.txt +0 -0
ucon/units.py
CHANGED
|
@@ -208,6 +208,11 @@ _UNIT_REGISTRY_CASE_SENSITIVE: Dict[str, Unit] = {}
|
|
|
208
208
|
# Prevents ambiguous parses like "min" -> milli-inch instead of minute.
|
|
209
209
|
_PRIORITY_ALIASES: set = {'min'}
|
|
210
210
|
|
|
211
|
+
# Priority scaled aliases that map to a specific (unit, scale) tuple.
|
|
212
|
+
# Used for medical conventions like "mcg" -> (gram, Scale.micro).
|
|
213
|
+
# Populated by _build_registry() after units are defined.
|
|
214
|
+
_PRIORITY_SCALED_ALIASES: Dict[str, Tuple[Unit, Scale]] = {}
|
|
215
|
+
|
|
211
216
|
# Scale prefix mapping (shorthand -> Scale)
|
|
212
217
|
# Sorted by length descending for greedy matching
|
|
213
218
|
_SCALE_PREFIXES: Dict[str, Scale] = {
|
|
@@ -260,6 +265,9 @@ def _build_registry() -> None:
|
|
|
260
265
|
_UNIT_REGISTRY[alias.lower()] = obj
|
|
261
266
|
_UNIT_REGISTRY_CASE_SENSITIVE[alias] = obj
|
|
262
267
|
|
|
268
|
+
# Register priority scaled aliases (medical conventions)
|
|
269
|
+
_PRIORITY_SCALED_ALIASES['mcg'] = (gram, Scale.micro) # microgram
|
|
270
|
+
|
|
263
271
|
|
|
264
272
|
def _parse_exponent(s: str) -> Tuple[str, float]:
|
|
265
273
|
"""
|
|
@@ -299,8 +307,8 @@ def _lookup_factor(s: str) -> Tuple[Unit, Scale]:
|
|
|
299
307
|
Look up a single unit factor, handling scale prefixes.
|
|
300
308
|
|
|
301
309
|
Prioritizes prefix+unit interpretation over direct unit lookup,
|
|
302
|
-
except for priority aliases (like 'min') which are checked first
|
|
303
|
-
to avoid ambiguous parses.
|
|
310
|
+
except for priority aliases (like 'min', 'mcg') which are checked first
|
|
311
|
+
to avoid ambiguous parses or to handle domain-specific conventions.
|
|
304
312
|
|
|
305
313
|
This means "kg" returns (gram, Scale.kilo) rather than (kilogram, Scale.one).
|
|
306
314
|
|
|
@@ -311,6 +319,7 @@ def _lookup_factor(s: str) -> Tuple[Unit, Scale]:
|
|
|
311
319
|
- 'kg' -> (gram, Scale.kilo)
|
|
312
320
|
- 'mL' -> (liter, Scale.milli)
|
|
313
321
|
- 'min' -> (minute, Scale.one) # priority alias, not milli-inch
|
|
322
|
+
- 'mcg' -> (gram, Scale.micro) # medical convention for microgram
|
|
314
323
|
|
|
315
324
|
Returns:
|
|
316
325
|
Tuple of (unit, scale).
|
|
@@ -318,7 +327,11 @@ def _lookup_factor(s: str) -> Tuple[Unit, Scale]:
|
|
|
318
327
|
Raises:
|
|
319
328
|
UnknownUnitError: If the unit cannot be resolved.
|
|
320
329
|
"""
|
|
321
|
-
# Check priority aliases first (
|
|
330
|
+
# Check priority scaled aliases first (e.g., "mcg" -> microgram)
|
|
331
|
+
if s in _PRIORITY_SCALED_ALIASES:
|
|
332
|
+
return _PRIORITY_SCALED_ALIASES[s]
|
|
333
|
+
|
|
334
|
+
# Check priority aliases (prevents "min" -> milli-inch)
|
|
322
335
|
if s in _PRIORITY_ALIASES:
|
|
323
336
|
if s in _UNIT_REGISTRY_CASE_SENSITIVE:
|
|
324
337
|
return _UNIT_REGISTRY_CASE_SENSITIVE[s], Scale.one
|
|
@@ -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=vKHGf5UX-g9t8dKy2IXgutHZD7W9frYdXSef_aPgZgo,17329
|
|
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.3.dist-info/licenses/LICENSE,sha256=LtimSYBSw1L_X6n1-VEdZRdwuROzPumrMUNX21asFuI,11356
|
|
12
|
+
ucon-0.6.3.dist-info/licenses/NOTICE,sha256=bh4fBOItio3kM4hSNYhqfFpcaAvOoixjD7Du8im-sYA,1079
|
|
13
|
+
ucon-0.6.3.dist-info/METADATA,sha256=8GNTOLltkPWCt68V7-dauFzK_e-XngBhCNlVXpBz_rw,17397
|
|
14
|
+
ucon-0.6.3.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
15
|
+
ucon-0.6.3.dist-info/entry_points.txt,sha256=jbfLf0FbOulgGa0nM_sRiTNfiCAkJcHnSSK_oj3g0cQ,50
|
|
16
|
+
ucon-0.6.3.dist-info/top_level.txt,sha256=Vv3KDuZ86fmH5yOYLbYap9DbBblK1YUkmlThffF71jA,5
|
|
17
|
+
ucon-0.6.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|