Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 937ba83

Browse filesBrowse files
committed
Privatize font_manager.JSONEncoder.
... with the usual deprecation dance. End users can still use json_dump, which provides the necessary functionality (the docstring was slightly updated at the same time); the point is to hide the (lengthy) docs of JSONEncoder from the docs.
1 parent ddd23a8 commit 937ba83
Copy full SHA for 937ba83

File tree

Expand file treeCollapse file tree

3 files changed

+27
-11
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+27
-11
lines changed
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Deprecations
2+
````````````
3+
4+
``font_manager.JSONEncoder`` is deprecated. Use `.font_manager.json_dump` to
5+
dump a `.FontManager` instance.

‎doc/missing-references.json

Copy file name to clipboardExpand all lines: doc/missing-references.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3504,7 +3504,7 @@
35043504
"matplotlib.dviread.Font": [
35053505
"<unknown>:1"
35063506
],
3507-
"json.encoder.JSONEncoder": [
3507+
"matplotlib.font_manager._JSONEncoder": [
35083508
"lib/matplotlib/font_manager.py:docstring of matplotlib.font_manager.JSONEncoder:1"
35093509
],
35103510
"font_manager.FontProperties": [

‎lib/matplotlib/font_manager.py

Copy file name to clipboardExpand all lines: lib/matplotlib/font_manager.py
+21-10Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ def copy(self):
858858
return new
859859

860860

861-
class JSONEncoder(json.JSONEncoder):
861+
class _JSONEncoder(json.JSONEncoder):
862862
def default(self, o):
863863
if isinstance(o, FontManager):
864864
return dict(o.__dict__, __class__='FontManager')
@@ -876,6 +876,11 @@ def default(self, o):
876876
return super().default(o)
877877

878878

879+
@cbook.deprecated("3.2", alternative="json_dump")
880+
class JSONEncoder(_JSONEncoder):
881+
pass
882+
883+
879884
def _json_decode(o):
880885
cls = o.pop('__class__', None)
881886
if cls is None:
@@ -896,26 +901,32 @@ def _json_decode(o):
896901

897902
def json_dump(data, filename):
898903
"""
899-
Dumps a data structure as JSON in the named file.
904+
Dump `FontManager` *data* as JSON to the file named *filename*.
905+
906+
Notes
907+
-----
908+
File paths that are children of the Matplotlib data path (typically, fonts
909+
shipped with Matplotlib) are stored relative to that data path (to remain
910+
valid across virtualenvs).
900911
901-
Handles FontManager and its fields. File paths that are children of the
902-
Matplotlib data path (typically, fonts shipped with Matplotlib) are stored
903-
relative to that data path (to remain valid across virtualenvs).
912+
See Also
913+
--------
914+
json_load
904915
"""
905916
with open(filename, 'w') as fh:
906917
try:
907-
json.dump(data, fh, cls=JSONEncoder, indent=2)
918+
json.dump(data, fh, cls=_JSONEncoder, indent=2)
908919
except OSError as e:
909920
_log.warning('Could not save font_manager cache {}'.format(e))
910921

911922

912923
def json_load(filename):
913924
"""
914-
Loads a data structure as JSON from the named file.
925+
Load a `FontManager` from the JSON file named *filename*.
915926
916-
Handles FontManager and its fields. Relative file paths are interpreted
917-
as being relative to the Matplotlib data path, and transformed into
918-
absolute paths.
927+
See Also
928+
--------
929+
json_dump
919930
"""
920931
with open(filename, 'r') as fh:
921932
return json.load(fh, object_hook=_json_decode)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.