Skip to content

Commit

Permalink
Type annotations: Image.py: Initial annotation for expression analyzer.
Browse files Browse the repository at this point in the history
  • Loading branch information
neiljp committed Aug 22, 2017
1 parent 15e9ebc commit 07549f2
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,21 +476,26 @@ def _getencoder(mode, encoder_name, args, extra=()):
# Simple expression analyzer

def coerce_e(value):
# type: (Any) -> _E ## FIXME TYPING: As detailed as possible?
return value if isinstance(value, _E) else _E(value)


class _E(object):
def __init__(self, data):
# type: (Any) -> None ## FIXME TYPING: As detailed as possible?
self.data = data

def __add__(self, other):
# type: (Any) -> _E ## FIXME TYPING: As detailed as possible?
return _E((self.data, "__add__", coerce_e(other).data))

def __mul__(self, other):
# type: (Any) -> _E ## FIXME TYPING: As detailed as possible?
return _E((self.data, "__mul__", coerce_e(other).data))


def _getscaleoffset(expr):
# type: (Any) -> Tuple[Any, Any] ## FIXME TYPING: Can be improved?
stub = ["stub"]
data = expr(_E(stub)).data
try:
Expand Down

0 comments on commit 07549f2

Please sign in to comment.