Title: get_backend() backward compatibility · Issue #11852 · matplotlib/matplotlib · GitHub
Open Graph Title: get_backend() backward compatibility · Issue #11852 · matplotlib/matplotlib
X Title: get_backend() backward compatibility · Issue #11852 · matplotlib/matplotlib
Description: Under matplotlib 3.0.0rc1, the return value of matplotlib.get_backend() is a sentinel object: In [2]: matplotlib.get_backend() Out[2]:
Open Graph Description: Under matplotlib 3.0.0rc1, the return value of matplotlib.get_backend() is a sentinel object: In [2]: matplotlib.get_backend() Out[2]:
X Description: Under matplotlib 3.0.0rc1, the return value of matplotlib.get_backend() is a sentinel object: In [2]: matplotlib.get_backend() Out[2]: <object at 0x111292d50> In [3]: backend = matplotlib.get...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/11852
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"get_backend() backward compatibility","articleBody":"Under matplotlib 3.0.0rc1, the return value of matplotlib.get_backend() is a sentinel object:\r\n\r\n```\r\nIn [2]: matplotlib.get_backend()\r\nOut[2]: \u003cobject at 0x111292d50\u003e\r\n\r\nIn [3]: backend = matplotlib.get_backend()\r\n\r\nIn [4]: backend.lower()\r\n---------------------------------------------------------------------------\r\nAttributeError Traceback (most recent call last)\r\n\u003cipython-input-4-f3c7164fcd07\u003e in \u003cmodule\u003e()\r\n----\u003e 1 backend.lower()\r\n\r\nAttributeError: 'object' object has no attribute 'lower'\r\n```\r\n\r\nUnder matplotlib 2.2.3 I get:\r\n\r\n```\r\nIn [1]: import matplotlib\r\n\r\nIn [2]: matplotlib.get_backend()\r\nOut[2]: 'MacOSX'\r\n\r\nIn [3]: backend = matplotlib.get_backend()\r\n\r\nIn [4]: backend.lower()\r\nOut[4]: 'macosx'\r\n```\r\n\r\nFor backward compatibility purposes it would be really nice if matplotlib 3.0.0 could return an object that at least acted like a string. In particular right now I'd like it to have a `lower()` method. I'd also like it if it had a nice `__repr__` or `__str__` implementation instead of printing out as an opaque object of type `object`.\r\n\r\nThe former is for backward compatibility, as the change breaks some of the yt plotting code --- in particular here's a failure from the test suite:\r\n\r\n```\r\n======================================================================\r\nERROR: Failure: AttributeError ('object' object has no attribute 'lower')\r\n----------------------------------------------------------------------\r\nTraceback (most recent call last):\r\n File \"/usr/local/lib/python3.7/site-packages/nose/failure.py\", line 39, in runTest\r\n raise self.exc_val.with_traceback(self.tb)\r\n File \"/usr/local/lib/python3.7/site-packages/nose/loader.py\", line 418, in loadTestsFromName\r\n addr.filename, addr.module)\r\n File \"/usr/local/lib/python3.7/site-packages/nose/importer.py\", line 47, in importFromPath\r\n return self.importFromDir(dir_path, fqname)\r\n File \"/usr/local/lib/python3.7/site-packages/nose/importer.py\", line 94, in importFromDir\r\n mod = load_module(part_fqname, fh, filename, desc)\r\n File \"/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/imp.py\", line 235, in load_module\r\n return load_source(name, filename, file)\r\n File \"/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/imp.py\", line 172, in load_source\r\n module = _load(spec)\r\n File \"\u003cfrozen importlib._bootstrap\u003e\", line 696, in _load\r\n File \"\u003cfrozen importlib._bootstrap\u003e\", line 677, in _load_unlocked\r\n File \"\u003cfrozen importlib._bootstrap_external\u003e\", line 728, in exec_module\r\n File \"\u003cfrozen importlib._bootstrap\u003e\", line 219, in _call_with_frames_removed\r\n File \"/Users/goldbaum/Documents/yt-git-fixes/yt/visualization/tests/test_color_maps.py\", line 23, in \u003cmodule\u003e\r\n class TestColorMaps(unittest.TestCase):\r\n File \"/Users/goldbaum/Documents/yt-git-fixes/yt/visualization/tests/test_color_maps.py\", line 34, in TestColorMaps\r\n @requires_backend('Agg')\r\n File \"/Users/goldbaum/Documents/yt-git-fixes/yt/testing.py\", line 1143, in requires_backend\r\n if backend.lower() == matplotlib.get_backend().lower():\r\nAttributeError: 'object' object has no attribute 'lower'\r\n```\r\n\r\nThis is code that's internal to yt's test suite, but I wouldn't be at all surprised if there's other code out there that assumes `matplotlib.get_backend()` returns a string. For example:\r\n\r\nhttps://github.com/search?q=matplotlib+get_backend+lower\u0026type=Code","author":{"url":"https://github.com/ngoldbaum","@type":"Person","name":"ngoldbaum"},"datePublished":"2018-08-13T20:39:43.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":8},"url":"https://github.com/11852/matplotlib/issues/11852"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:e41d67bb-7520-aa7e-6ca0-9eef0033538d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9432:1748BD:3F9E230:5A0024C:6A56C9BF |
| html-safe-nonce | c264bfe84846734708396c8515e038d2708d90e1386f576d3f548b271bd61b3c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NDMyOjE3NDhCRDozRjlFMjMwOjVBMDAyNEM6NkE1NkM5QkYiLCJ2aXNpdG9yX2lkIjoiNTQwOTEyMTAzMTcxMjg1MjQxNSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 98b98b8cae1e191fb76bcf1a759e0af39fcc75dc2f33b7454f4634bedbe54b85 |
| hovercard-subject-tag | issue:350185460 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/matplotlib/matplotlib/11852/issue_layout |
| twitter:image | https://opengraph.githubassets.com/22d0a115e795f5b77c428cc361b2b6828a82f21a33195eb96fe0a9470a118049/matplotlib/matplotlib/issues/11852 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/22d0a115e795f5b77c428cc361b2b6828a82f21a33195eb96fe0a9470a118049/matplotlib/matplotlib/issues/11852 |
| og:image:alt | Under matplotlib 3.0.0rc1, the return value of matplotlib.get_backend() is a sentinel object: In [2]: matplotlib.get_backend() Out[2]: |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ngoldbaum |
| hostname | github.com |
| expected-hostname | github.com |
| None | df99b7164e1d961b639cf5d3cbd6b5ba673edc67bd7e47cdc4746b96099e11ae |
| turbo-cache-control | no-preview |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 3146ab55fc8763ab0e1d2a875e600b3a545bc751 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width