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

Skip to content

Commit bcdfab5

Browse files
committed
Be more pythonic - fail safely rather than prevent failure
Some image types may not be handled. OS updates may change which image types are valid. Rather than check, the code will fail if pdf's aren't allowed. If we need more complexity than that, we can update the code.
1 parent 371c32e commit bcdfab5

File tree

2 files changed

+1
-25
lines changed

2 files changed

+1
-25
lines changed

lib/matplotlib/backends/backend_macosx.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ class FigureManagerMac(_macosx.FigureManager, FigureManagerBase):
6666
Wrap everything up into a window for the pylab interface
6767
"""
6868
def __init__(self, canvas, num):
69-
icon_path = None
70-
if 'com.adobe.pdf' in _macosx.FigureManager._get_image_types():
71-
icon_path = str(cbook._get_data_path('images/matplotlib.pdf'))
69+
icon_path = str(cbook._get_data_path('images/matplotlib.pdf'))
7270
_macosx.FigureManager.__init__(self, canvas, icon_path)
7371
FigureManagerBase.__init__(self, canvas, num)
7472
if mpl.rcParams['toolbar'] == 'toolbar2':

src/_macosx.m

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -817,23 +817,6 @@ int set_icon(PyObject* icon_path) {
817817
Py_RETURN_NONE;
818818
}
819819

820-
static PyObject*
821-
FigureManager__get_image_types(PyObject* no_self, PyObject* no_args)
822-
{
823-
NSArray<NSString*>* images = NSImage.imageUnfilteredTypes;
824-
const NSUInteger n_images = [images count];
825-
PyObject* out = PyList_New(n_images);
826-
if (!out) {
827-
[images release];
828-
return NULL;
829-
}
830-
for (NSUInteger i=0; i < n_images; ++i) {
831-
const char* string = images[i].UTF8String;
832-
PyList_SET_ITEM(out, i, PyUnicode_FromString(string));
833-
}
834-
return out;
835-
}
836-
837820
static PyMethodDef FigureManager_methods[] = {
838821
{"show",
839822
(PyCFunction)FigureManager_show,
@@ -860,11 +843,6 @@ int set_icon(PyObject* icon_path) {
860843
METH_VARARGS,
861844
NULL, // docstring inherited.
862845
},
863-
{"_get_image_types",
864-
FigureManager__get_image_types,
865-
METH_STATIC | METH_NOARGS,
866-
"Return image types supported by macOS"
867-
},
868846
{NULL} /* Sentinel */
869847
};
870848

0 commit comments

Comments
 (0)