Skip to content

"if 1:" blocks in examples #12191

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

Closed
timhoffm opened this issue Sep 20, 2018 · 9 comments
Closed

"if 1:" blocks in examples #12191

timhoffm opened this issue Sep 20, 2018 · 9 comments
Labels
Difficulty: Easy https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues Good first issue Open a pull request against these issues if there are no active ones!
Milestone

Comments

@timhoffm
Copy link
Member

Bug report

Some examples contain code in an if 1: block.

e.g. https://matplotlib.org/devdocs/gallery/axisartist/demo_axisline_style.html
or https://matplotlib.org/devdocs/gallery/event_handling/pick_event_demo.html

IMO this does not make sense and is rather confusing for the reader.

The condition should simply be removed for trivial cases, or replaced by functions if appropriate.

@timhoffm timhoffm added Difficulty: Easy https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues Good first issue Open a pull request against these issues if there are no active ones! labels Sep 20, 2018
@timhoffm timhoffm changed the title if 1: blocks in examples "if 1:" blocks in examples Sep 20, 2018
@tacaswell tacaswell added this to the v3.0.x milestone Sep 21, 2018
@tacaswell
Copy link
Member

👍

@abhinuvpitale
Copy link
Contributor

abhinuvpitale commented Sep 22, 2018

I can do this, should I take it up?
It should be replaced with __name__ == '__main__', right?

@timhoffm
Copy link
Member Author

You are welcome to do this! 👍

Concerning, __name__ == '__main__' I don't think we have a strict policy here. As a rule of thumb, I would not add that if the example is more snippet-like.

E.g. for https://matplotlib.org/devdocs/gallery/axisartist/demo_axisline_style.html I would just remove the conditional and dedent.

OTOH, more program like examples such as https://matplotlib.org/devdocs/gallery/misc/demo_agg_filter.html?highlight=agg%20filter definitively call for __name__ == '__main__'.

@abhinuvpitale
Copy link
Contributor

added the commits @timhoffm, please review!

QuLogic pushed a commit that referenced this issue Sep 25, 2018
* change proposed in issue #12191

removed the confusing if 1: as propsed in #12191

* change requested in #12191

* added main() to resolve comments from #12191

* update #12191

* flake-8 corrections #12191

* update ```plt.show``` for #12191

* flake8 update #12191
@QuLogic
Copy link
Member

QuLogic commented Sep 25, 2018

Fixed by #12222.

@QuLogic QuLogic closed this as completed Sep 25, 2018
@QuLogic
Copy link
Member

QuLogic commented Sep 25, 2018

Oops, no, that didn't catch all of them:

$ rg 'if 1' examples/
examples/text_labels_and_annotations/demo_annotation_box.py
16:if 1:

examples/misc/demo_agg_filter.py
310:if 1:

examples/text_labels_and_annotations/demo_text_rotation_mode.py
45:if 1:

examples/misc/patheffect_demo.py
11:if 1:

examples/text_labels_and_annotations/demo_text_path.py
59:if 1:

examples/axisartist/demo_curvelinear_grid.py
134:if 1:

examples/axisartist/demo_curvelinear_grid2.py
67:if 1:

@QuLogic QuLogic reopened this Sep 25, 2018
@abhinuvpitale
Copy link
Contributor

Let me add them, might take some time!

@eric-wieser
Copy link
Contributor

eric-wieser commented Sep 26, 2018

I think I know why this exists - it's a trick I use to paste multiple lines of code into IDLE, which unlike IPython refuses to run any of them if there are non-indented newlines

QuLogic pushed a commit that referenced this issue Sep 27, 2018
* change proposed in issue #12191

removed the confusing if 1: as propsed in #12191

* change requested in #12191

* added main() to resolve comments from #12191

* update #12191

* flake-8 corrections #12191

* update ```plt.show``` for #12191

* flake8 update #12191

* Update demo_annotation_box.py

* Update demo_agg_filter.py

* Update patheffect_demo.py

* Update demo_text_rotation_mode.py

* Update demo_text_path.py

* Update demo_curvelinear_grid.py

* Update demo_curvelinear_grid2.py

* flake8 compliant

* flake8 compliant

* flake8 compliant

* Update patheffect_demo.py

* Update demo_annotation_box.py

* flake8 compliant

* Update demo_text_rotation_mode.py

* Update patheffect_demo.py

* Update demo_annotation_box.py
@QuLogic
Copy link
Member

QuLogic commented Sep 27, 2018

Now complete with #12260.

@QuLogic QuLogic closed this as completed Sep 27, 2018
@QuLogic QuLogic modified the milestones: v3.0.x, v3.1 Sep 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Difficulty: Easy https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues Good first issue Open a pull request against these issues if there are no active ones!
Projects
None yet
Development

No branches or pull requests

5 participants