python-fire icon indicating copy to clipboard operation
python-fire copied to clipboard

change in behaviour, optimize code

Open tusharnankani opened this issue 3 years ago • 4 comments

tusharnankani avatar Dec 25 '20 06:12 tusharnankani

Thanks for the PR. 🙏 We generally don’t accept changes to the console module directly in the fire repo though, in order to keep any diffs between it and its upstream source easy to reason about.

Is there a reason to prefer AssertionErrors over asserts?

dbieber avatar Dec 25 '20 14:12 dbieber

Is there a reason to prefer AssertionErrors over asserts?

Whenever the use of assert is detected, the enclosed code will be removed when compiling to optimized byte code. The assert statement is generally for unit-testing or finding issues during the development process. This does not mean you will necessarily see the error. On the other hand, raising an AssertionError means that the error will be raised by the code and that any calling processes can deal with this error as needed.

Usage of assert statement in application logic is discouraged. assert is removed with compiling to optimised byte code (python -o producing *.pyo files). Consider raising an exception instead. Ideally, assert statement should be used only in tests.

References for the same^ https://stackoverflow.com/questions/48408692/raise-assertionerror-vs-assert-python https://deepsource.io/docs/config/deepsource-toml.html#test-patterns https://stackoverflow.com/questions/40182944/difference-between-raise-try-and-assert https://github.com/plyara/plyara/issues/78

We generally don’t accept changes to the console module directly in the fire repo though, in order to keep any diffs between it and its upstream source easy to reason about.

Apologies from my end, I wasn't aware of that. Let me know what should I do next?

tusharnankani avatar Dec 25 '20 14:12 tusharnankani

@dbieber Any updates?

tusharnankani avatar Dec 29 '20 16:12 tusharnankani

Apologies from my end, I wasn't aware of that.

No worries! There was no way for you to know.

@dbieber Any updates?

I'll let you know about making changes to console if I figure it out in the new year. Otherwise, no action to take on your part for now.

dbieber avatar Dec 29 '20 18:12 dbieber