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

Incorrect usage of python assertions #1134

Open
Bain-OS opened this issue Jun 12, 2024 · 2 comments
Open

Incorrect usage of python assertions #1134

Bain-OS opened this issue Jun 12, 2024 · 2 comments

Comments

@Bain-OS
Copy link

Bain-OS commented Jun 12, 2024

The way python assert statements are used here is potentially not correct. These should be raising exceptions instead

See these for example, I have not done an exhaustive search
https://github.com/stanfordnlp/dspy/blob/main/dsp/templates/template_v2.py#L102
https://github.com/stanfordnlp/dspy/blob/main/dsp/templates/template_v2.py#L188

The reason this usage is incorrect: when deploying production python codebase it is good to set the optimize flag which removes asserts. i.e asserts should only be used as a development/debugging tool

see more here https://docs.datadoghq.com/code_analysis/static_analysis_rules/python-best-practices/no-assert/

@arnavsinghvi11
Copy link
Collaborator

Hi @Bain-OS , thanks for raising this. These asserts were set up for the open-source development and testing of DSPy. Definitely agree that these should be removed in production environments, and it would be great if you have any ideas on keeping a flag for this within the codebase to make DSPy production ready. Feel free to open a PR on it!

@tom-doerr
Copy link
Contributor

I think @Bain-OS is worried about the exact opposite.
When you run a Python program in production you can set the optimize flag (-O) which results, among other things, in asserts being removed.
This would mean no errors are thrown for the cases the asserts are checking for in production.
I however can't tell if that is unwanted behavior or actually wanted in this case.

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

3 participants