Skip to content

Code optimizations #1924

Discussion options

You must be logged in to vote

I think the only sensible approach is case-by-case.

Generally I'd optimise for readability over micro-optimisation, but for the specific case perhaps? they're two equally decent formulations...

    @classmethod
    def is_success(cls, value: int) -> bool:
        """
        Returns `True` for 2xx status codes, `False` otherwise.
        """
        return 200 <= value <= 299

vs.

    @classmethod
    def is_success(cls, value: int) -> bool:
        """
        Returns `True` for 2xx status codes, `False` otherwise.
        """
        return value // 100 == 2

Writing this now, and looking at them side by side I guess I'd tend to suggest just sticking with the first. But there's no specifi…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by StephenBrown2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants