omdev 0.0.0.dev429__py3-none-any.whl → 0.0.0.dev431__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.
omdev/scripts/interp.py CHANGED
@@ -1407,36 +1407,66 @@ class NamedLogLevel(int):
1407
1407
 
1408
1408
  #
1409
1409
 
1410
- @property
1411
- def exact_name(self) -> ta.Optional[str]:
1412
- return self._NAMES_BY_INT.get(self)
1410
+ _CACHE: ta.ClassVar[ta.MutableMapping[int, 'NamedLogLevel']] = {}
1411
+
1412
+ @ta.overload
1413
+ def __new__(cls, name: str, offset: int = 0, /) -> 'NamedLogLevel':
1414
+ ...
1415
+
1416
+ @ta.overload
1417
+ def __new__(cls, i: int, /) -> 'NamedLogLevel':
1418
+ ...
1419
+
1420
+ def __new__(cls, x, offset=0, /):
1421
+ if isinstance(x, str):
1422
+ return cls(cls._INTS_BY_NAME[x.upper()] + offset)
1423
+ elif not offset and (c := cls._CACHE.get(x)) is not None:
1424
+ return c
1425
+ else:
1426
+ return super().__new__(cls, x + offset)
1427
+
1428
+ #
1413
1429
 
1414
- _effective_name: ta.Optional[str]
1430
+ _name_and_offset: ta.Tuple[str, int]
1415
1431
 
1416
1432
  @property
1417
- def effective_name(self) -> ta.Optional[str]:
1433
+ def name_and_offset(self) -> ta.Tuple[str, int]:
1418
1434
  try:
1419
- return self._effective_name
1435
+ return self._name_and_offset
1420
1436
  except AttributeError:
1421
1437
  pass
1422
1438
 
1423
- if (n := self.exact_name) is None:
1439
+ if (n := self._NAMES_BY_INT.get(self)) is not None:
1440
+ t = (n, 0)
1441
+ else:
1424
1442
  for n, i in self._NAME_INT_PAIRS: # noqa
1425
1443
  if self >= i:
1444
+ t = (n, (self - i))
1426
1445
  break
1427
1446
  else:
1428
- n = None
1447
+ t = ('NOTSET', int(self))
1448
+
1449
+ self._name_and_offset = t
1450
+ return t
1451
+
1452
+ @property
1453
+ def exact_name(self) -> ta.Optional[str]:
1454
+ n, o = self.name_and_offset
1455
+ return n if not o else None
1429
1456
 
1430
- self._effective_name = n
1457
+ @property
1458
+ def effective_name(self) -> str:
1459
+ n, _ = self.name_and_offset
1431
1460
  return n
1432
1461
 
1433
1462
  #
1434
1463
 
1435
- def __repr__(self) -> str:
1436
- return f'{self.__class__.__name__}({int(self)})'
1437
-
1438
1464
  def __str__(self) -> str:
1439
- return self.exact_name or f'{self.effective_name or "INVALID"}:{int(self)}'
1465
+ return self.exact_name or f'{self.effective_name}{int(self):+}'
1466
+
1467
+ def __repr__(self) -> str:
1468
+ n, o = self.name_and_offset
1469
+ return f'{self.__class__.__name__}({n!r}{f", {int(o)}" if o else ""})'
1440
1470
 
1441
1471
  #
1442
1472
 
@@ -1456,6 +1486,9 @@ NamedLogLevel.DEBUG = NamedLogLevel(logging.DEBUG)
1456
1486
  NamedLogLevel.NOTSET = NamedLogLevel(logging.NOTSET)
1457
1487
 
1458
1488
 
1489
+ NamedLogLevel._CACHE.update({i: NamedLogLevel(i) for i in NamedLogLevel._NAMES_BY_INT}) # noqa
1490
+
1491
+
1459
1492
  ########################################
1460
1493
  # ../../../omlish/logs/std/filters.py
1461
1494
 
@@ -2826,6 +2859,7 @@ class PredicateTimeout(Timeout):
2826
2859
  ##
2827
2860
 
2828
2861
 
2862
+ @ta.runtime_checkable
2829
2863
  class LoggerLike(ta.Protocol):
2830
2864
  """Satisfied by both our Logger and stdlib logging.Logger."""
2831
2865