Python icon indicating copy to clipboard operation
Python copied to clipboard

Remove print statements within functions

Open CaedenPH opened this issue 3 years ago • 1 comments

Feature description

Use flake8-print plugin to check for print statements and remove them if found within variable scopes

CaedenPH avatar Oct 16 '22 19:10 CaedenPH

I think this will be difficult to explain to new contributors.

cclauss avatar Oct 16 '22 19:10 cclauss

I've run flake8 with flake8-print and the print statements I've checked are all in if __name__ == "__main__" blocks. They're mainly just used for running functions on user inputs. I assume these print statements should stay?

tianyizheng02 avatar Oct 17 '22 22:10 tianyizheng02

Yes, they can remain as they are. CONTRIBUTING.md says that algorithmic functions should not input(), print(), plot, or read/write to files. However, there might be __main__, or main(), or other utility functions that do these things.

cclauss avatar Oct 18 '22 02:10 cclauss

Instead, I propose to make the following refactor:

For all the classes that provide some method to print out a representation of that object, use __str__ method to return the string representation instead. The caller then can do whatever he/she wants, print it, etc.

dhruvmanila avatar Oct 21 '22 11:10 dhruvmanila

Hello sir, can u assign me this issue. I would love to grab this opportunity.

SwaggyRajput avatar Oct 22 '22 15:10 SwaggyRajput

Please stop waiting. We do not assign issues in this repo. Instead, we review pull requests so if you see something that is worth fixing then please create a pull request to fix it. #7499 (merged) seems to have solved most of these problems.

cclauss avatar Oct 22 '22 16:10 cclauss