Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong use of assert statements #89

Open
sebtrack opened this issue May 27, 2021 · 0 comments
Open

Wrong use of assert statements #89

sebtrack opened this issue May 27, 2021 · 0 comments

Comments

@sebtrack
Copy link

sebtrack commented May 27, 2021

I noticed that there are assert statements that are catched wrongly, if an assert statement fails it throws an AssertionError not ValueError nor KeyError.

rrcf/rrcf/rrcf.py

Lines 429 to 438 in 34504c1

try:
assert (point.size == self.ndim)
except ValueError:
raise ValueError(
"Point must be same dimension as existing points in tree.")
# Check for existing index in leaves dict
try:
assert (index not in self.leaves)
except KeyError:
raise KeyError("Index already exists in leaves dict.")

Also consider removing all assert statements, because they are ignored if __debug__ is not True. This is the case when you run in production (See Docs).

The lines could be rewritten as:

        if not point.size == self.ndim:
            raise ValueError(
                "Point must be same dimension as existing points in tree.")
        # Check for existing index in leaves dict
        try:
            self.leaves[index]
        except KeyError:
            raise KeyError("Index already exists in leaves dict.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant