Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions lib/mpl_toolkits/axes_grid1/axes_size.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
Note that this class is nothing more than a simple tuple of two
floats. Take a look at the Divider class to see how these two
values are used.

Once created, the unit classes can be modified by simple arithmetic
operations: addition /subtraction with another unit type or a real number and scaling
(multiplication or division) by a real number.
"""

from numbers import Real
Expand All @@ -17,14 +21,33 @@

class _Base:
def __rmul__(self, other):
return self * other

def __mul__(self, other):
if not isinstance(other, Real):
return NotImplemented

Check warning on line 28 in lib/mpl_toolkits/axes_grid1/axes_size.py

View check run for this annotation

Codecov / codecov/patch

lib/mpl_toolkits/axes_grid1/axes_size.py#L28

Added line #L28 was not covered by tests
return Fraction(other, self)

def __div__(self, other):
return (1 / other) * self

Check warning on line 32 in lib/mpl_toolkits/axes_grid1/axes_size.py

View check run for this annotation

Codecov / codecov/patch

lib/mpl_toolkits/axes_grid1/axes_size.py#L32

Added line #L32 was not covered by tests

def __add__(self, other):
if isinstance(other, _Base):
return Add(self, other)
else:
return Add(self, Fixed(other))

def __neg__(self):
return -1 * self

Check warning on line 41 in lib/mpl_toolkits/axes_grid1/axes_size.py

View check run for this annotation

Codecov / codecov/patch

lib/mpl_toolkits/axes_grid1/axes_size.py#L41

Added line #L41 was not covered by tests

def __radd__(self, other):
# other cannot be a _Base instance, because A + B would trigger
# A.__add__(B) first.
return Add(self, Fixed(other))

Check warning on line 46 in lib/mpl_toolkits/axes_grid1/axes_size.py

View check run for this annotation

Codecov / codecov/patch

lib/mpl_toolkits/axes_grid1/axes_size.py#L46

Added line #L46 was not covered by tests

def __sub__(self, other):
return self + (-other)

Check warning on line 49 in lib/mpl_toolkits/axes_grid1/axes_size.py

View check run for this annotation

Codecov / codecov/patch

lib/mpl_toolkits/axes_grid1/axes_size.py#L49

Added line #L49 was not covered by tests

def get_size(self, renderer):
"""
Return two-float tuple with relative and absolute sizes.
Expand Down
Loading