ucon 0.6.2__py3-none-any.whl → 0.6.4__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 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,10 @@ 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
+ _PRIORITY_SCALED_ALIASES['cc'] = (liter, Scale.milli) # cubic centimeter = 1 mL
271
+
263
272
 
264
273
  def _parse_exponent(s: str) -> Tuple[str, float]:
265
274
  """
@@ -299,8 +308,8 @@ def _lookup_factor(s: str) -> Tuple[Unit, Scale]:
299
308
  Look up a single unit factor, handling scale prefixes.
300
309
 
301
310
  Prioritizes prefix+unit interpretation over direct unit lookup,
302
- except for priority aliases (like 'min') which are checked first
303
- to avoid ambiguous parses.
311
+ except for priority aliases (like 'min', 'mcg') which are checked first
312
+ to avoid ambiguous parses or to handle domain-specific conventions.
304
313
 
305
314
  This means "kg" returns (gram, Scale.kilo) rather than (kilogram, Scale.one).
306
315
 
@@ -311,6 +320,7 @@ def _lookup_factor(s: str) -> Tuple[Unit, Scale]:
311
320
  - 'kg' -> (gram, Scale.kilo)
312
321
  - 'mL' -> (liter, Scale.milli)
313
322
  - 'min' -> (minute, Scale.one) # priority alias, not milli-inch
323
+ - 'mcg' -> (gram, Scale.micro) # medical convention for microgram
314
324
 
315
325
  Returns:
316
326
  Tuple of (unit, scale).
@@ -318,7 +328,11 @@ def _lookup_factor(s: str) -> Tuple[Unit, Scale]:
318
328
  Raises:
319
329
  UnknownUnitError: If the unit cannot be resolved.
320
330
  """
321
- # Check priority aliases first (prevents "min" -> milli-inch)
331
+ # Check priority scaled aliases first (e.g., "mcg" -> microgram)
332
+ if s in _PRIORITY_SCALED_ALIASES:
333
+ return _PRIORITY_SCALED_ALIASES[s]
334
+
335
+ # Check priority aliases (prevents "min" -> milli-inch)
322
336
  if s in _PRIORITY_ALIASES:
323
337
  if s in _UNIT_REGISTRY_CASE_SENSITIVE:
324
338
  return _UNIT_REGISTRY_CASE_SENSITIVE[s], Scale.one
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ucon
3
- Version: 0.6.2
3
+ Version: 0.6.4
4
4
  Summary: A tool for dimensional analysis: a 'Unit CONverter'
5
5
  Home-page: https://github.com/withtwoemms/ucon
6
6
  Author: Emmanuel I. Obi
@@ -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=3reuG-G-BAAOiH_es8CE5jxAFTg5bkrd2JQ5C1iBTFg,16676
8
+ ucon/units.py,sha256=T410Haid7PBLKQgxEfUGKheOAj61E3gRCau4aw0NNJM,17414
9
9
  ucon/mcp/__init__.py,sha256=WoFOQ7JeDIzbjjkFIJ0Uv53VVLu-4lrjzG5vpVGGfT4,123
10
10
  ucon/mcp/server.py,sha256=uUrdevEaR65Qjh9xn8Q-_IusNjPGxdkLF9iQmiSTs0g,7016
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,,
11
+ ucon-0.6.4.dist-info/licenses/LICENSE,sha256=LtimSYBSw1L_X6n1-VEdZRdwuROzPumrMUNX21asFuI,11356
12
+ ucon-0.6.4.dist-info/licenses/NOTICE,sha256=bh4fBOItio3kM4hSNYhqfFpcaAvOoixjD7Du8im-sYA,1079
13
+ ucon-0.6.4.dist-info/METADATA,sha256=gdY9jvge5vPs_uocKQHXM-TB3Pq-Dw877y3nCdQYhGs,17397
14
+ ucon-0.6.4.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
15
+ ucon-0.6.4.dist-info/entry_points.txt,sha256=jbfLf0FbOulgGa0nM_sRiTNfiCAkJcHnSSK_oj3g0cQ,50
16
+ ucon-0.6.4.dist-info/top_level.txt,sha256=Vv3KDuZ86fmH5yOYLbYap9DbBblK1YUkmlThffF71jA,5
17
+ ucon-0.6.4.dist-info/RECORD,,
File without changes