forked from iterative/dvc
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
benedict: monkeypatch, performance improvements, bugfixes
Fixes iterative#6476, fixes iterative#6423 and closes iterative#6484.
- Loading branch information
Showing
4 changed files
with
51 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
""" | ||
Rollbacks monkeypatching of `json.encoder` by benedict. | ||
It monkeypatches json to use Python-based encoder instead of C-based | ||
during import. | ||
We rollback that monkeypatch by keeping reference to that C-based | ||
encoder and reinstate them after importing benedict. | ||
See: https://github.com/iterative/dvc/issues/6423 | ||
https://github.com/fabiocaccamo/python-benedict/issues/62 | ||
and the source of truth: | ||
https://github.com/fabiocaccamo/python-benedict/blob/c98c471065/benedict/dicts/__init__.py#L282-L285 | ||
""" | ||
from json import encoder | ||
|
||
try: | ||
c_make_encoder = encoder.c_make_encoder # type: ignore[attr-defined] | ||
except AttributeError: | ||
c_make_encoder = None | ||
|
||
|
||
from benedict import benedict # noqa: E402 | ||
|
||
encoder.c_make_encoder = c_make_encoder # type: ignore[attr-defined] | ||
# Please import benedict from here lazily | ||
__all__ = ["benedict"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters