-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move around some things to stop data being copied. Reduce memory for when no source maps are created.
- Loading branch information
Showing
3 changed files
with
80 additions
and
75 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from decimal import Decimal | ||
# From http://bugs.python.org/issue16535 | ||
class NumberStr(float): | ||
def __init__(self, o): | ||
# We don't call the parent here, since we're deliberately altering it's functionality | ||
# pylint: disable=W0231 | ||
self.o = o | ||
|
||
def __repr__(self): | ||
return str(self.o) | ||
|
||
# This is needed for this trick to work in python 3.4 | ||
def __float__(self): | ||
return self | ||
|
||
class Cell: | ||
__slots__ = ['cell_value', 'cell_location', 'sub_cells'] | ||
def __init__(self, cell_value, cell_location): | ||
self.cell_value = cell_value | ||
self.cell_location = cell_location | ||
self.sub_cells = [] | ||
|
||
def decimal_default(o): | ||
if isinstance(o, Decimal): | ||
return NumberStr(o) | ||
if isinstance(o, Cell): | ||
return o.cell_value | ||
raise TypeError(repr(o) + " is not JSON serializable") |