Cache SmartErrorCode creation (#1022)

Uses the python 3.9 cache feature to improve performance of error code creation
This commit is contained in:
J. Nick Koston
2024-06-30 04:49:59 -05:00
committed by GitHub
parent 2a62849987
commit 368590cd36
3 changed files with 11 additions and 5 deletions

View File

@@ -4,6 +4,7 @@ from __future__ import annotations
from asyncio import TimeoutError as _asyncioTimeoutError
from enum import IntEnum
from functools import cache
from typing import Any
@@ -63,6 +64,12 @@ class SmartErrorCode(IntEnum):
def __str__(self):
return f"{self.name}({self.value})"
@staticmethod
@cache
def from_int(value: int) -> SmartErrorCode:
"""Convert an integer to a SmartErrorCode."""
return SmartErrorCode(value)
SUCCESS = 0
# Transport Errors