Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Don't index into __builtins__ (not supported by PyPy). #8331

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

Merged
merged 1 commit into from
Mar 20, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6103,6 +6103,10 @@ def hist(self, x, bins=None, range=None, normed=False, weights=None,
.. plot:: mpl_examples/statistics/histogram_demo_features.py

"""
# Avoid shadowing the builtin.
bin_range = range
del range

def _normalize_input(inp, ename='input'):
"""Normalize 1 or 2d input into list of np.ndarray or
a single 2D np.ndarray.
Expand Down Expand Up @@ -6147,13 +6151,6 @@ def _normalize_input(inp, ename='input'):
if bins is None:
bins = rcParams['hist.bins']

# xrange becomes range after 2to3
bin_range = range
Copy link
Member

Choose a reason for hiding this comment

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

I have a slight preference for

bin_range = range
del range

It causes less code churn and keeps the code below clearer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sounds reasonable, fixed

range = __builtins__["range"]

# NOTE: the range keyword overwrites the built-in func range !!!
# needs to be fixed in numpy !!!

# Validate string inputs here so we don't have to clutter
# subsequent code.
if histtype not in ['bar', 'barstacked', 'step', 'stepfilled']:
Expand Down Expand Up @@ -6514,10 +6511,7 @@ def hist2d(self, x, y, bins=10, range=None, normed=False, weights=None,
.. plot:: mpl_examples/statistics/plot_hist.py
"""

# xrange becomes range after 2to3
bin_range = range
range = __builtins__["range"]
h, xedges, yedges = np.histogram2d(x, y, bins=bins, range=bin_range,
h, xedges, yedges = np.histogram2d(x, y, bins=bins, range=range,
normed=normed, weights=weights)

if cmin is not None:
Expand Down