Skip to content

Change isinstance checks into asserts or __debug__ blocks #1244

@einarf

Description

@einarf

We have quite a bit of isinstance testing to sanity check parameters around the code base. For example in collision methods. These are very expensive and we should consider changeing some of the into assert or debug blocks.

# Assert with custom user message
assert isinstance(a, b), "Message to user"

# Debug block
if __debug__:
    if not isinstance(a, b):
        raise ValueErrror("Message to user")

Asserts and the entire __debug__ block will be purge when running python with -O option or the PYTHONOPTIMIZE environment variable is set.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions