Skip to content

What is the purpose of @cache on snap7.error.check_error()? #551

@mthuurne

Description

@mthuurne

I was reading through the source code while doing a migration from python-snap7 version 1 to 2 and noticed this:
(docstring omitted for brevity)

@cache
def check_error(code: int, context: Context = "client") -> None:
    if code and code != 1:
        error = error_text(code, context)
        logger.error(error)
        raise RuntimeError(error)

In the case of an error, this function raises an exception, which means there is no return value to cache. Therefore only the returning of None when code is 0 or 1 will be cached, but that's such a simple case to handle that I think caching might make things slower rather than faster.

Perhaps the error_text() function would be more suitable to apply @cache to?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions