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

Fix S101 Use of assert detected #1783

Merged
merged 1 commit into from
Dec 14, 2023
Merged

Fix S101 Use of assert detected #1783

merged 1 commit into from
Dec 14, 2023

Conversation

brianhelba
Copy link
Collaborator

In non-test parts of the codebase, assert shouldn't be used. See https://docs.astral.sh/ruff/rules/assert/ for rationale.

settings.DANDI_DANDISETS_LOG_BUCKET_NAME,
settings.DANDI_DANDISETS_EMBARGO_LOG_BUCKET_NAME,
]
}:
raise ValueError(f'Non-log bucket: {bucket}')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you choose a ValueError here, but RuntimeError for the same error below?

Also, why the change from a list to a set?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that the order of the buckets is irrelevant, which I'm guessing is why it was converted, but I've come to really dislike the braces-style set syntax. I hardly see it used in the wild and it doesn't work for empty sets, which just makes it confusing IMO.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For those cases, since the problem was directly caused by the given value of a parameter, ValueError seemed like a better fit:

Raised when an operation or function receives an argument that has the right type but an inappropriate value, and the situation is not described by a more precise exception such as IndexError.

The more generic exception is RuntimeError:

Raised when an error is detected that doesn’t fall in any of the other categories. The associated value is a string indicating what precisely went wrong.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made it a set because that's a more appropriate collection for things which have no ordering and where membership testing is a primary consideration. Certainly here, it makes no real difference either way.

@brianhelba brianhelba merged commit 944567a into master Dec 14, 2023
10 checks passed
@brianhelba brianhelba deleted the assert branch December 14, 2023 21:33
@dandibot
Copy link
Member

🚀 PR was released in v0.3.68 🚀

@dandibot dandibot added the released This issue/pull request has been released. label Dec 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released This issue/pull request has been released.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants