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 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 (prevents "min" -> milli-inch)
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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ucon
3
- Version: 0.6.2
3
+ Version: 0.6.3
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=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.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.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