Normalize a stored priority value for sorting and display. Corrupted registry data may contain missing, non-numeric, non-positive, or boolean values. In those cases, fall back to the default priority. Args: value: Priority value to normalize (may be int, str, None, etc.)
(value: Any, default: int = DEFAULT_HOOK_PRIORITY)
| 120 | |
| 121 | |
| 122 | def normalize_priority(value: Any, default: int = DEFAULT_HOOK_PRIORITY) -> int: |
| 123 | """Normalize a stored priority value for sorting and display. |
| 124 | |
| 125 | Corrupted registry data may contain missing, non-numeric, non-positive, or |
| 126 | boolean values. In those cases, fall back to the default priority. |
| 127 | |
| 128 | Args: |
| 129 | value: Priority value to normalize (may be int, str, None, etc.) |
| 130 | default: Default priority to use for invalid values |
| 131 | |
| 132 | Returns: |
| 133 | Normalized priority as positive integer (>= 1) |
| 134 | """ |
| 135 | if isinstance(value, bool): |
| 136 | return default |
| 137 | try: |
| 138 | priority = int(value) |
| 139 | except (TypeError, ValueError): |
| 140 | return default |
| 141 | return priority if priority >= 1 else default |
| 142 | |
| 143 | |
| 144 | def coerce_hook_entries(hook_config: Any) -> List[Any]: |
no outgoing calls