Commit 7e5d6c25 authored by Yong Tang's avatar Yong Tang
Browse files

Add a better error message when unsupported ops are used for Dimension

This fix is related to 25790. In 25790, `Dimension` with division will
thrown an TypeError:
```
output_dim = input_shape[-1] / 2
...
TypeError: unsupported operand type(s) for /: 'Dimension' and 'int'
```
The error is expected, as Dimension only support `//` (not `/`).

However, for backward compatible reasons, `__div__`(`/`) is actually
implemented (but deprecated). See code.

This issue causes confusion and it has been mentioned multiple times
in GitHub and StackOverflow(https://stackoverflow.com/questions/51692253/typeerror-unsupported-operand-types-for-dimension-and-int

)

This fix is an attempt to print a better error message with:
```
TypeError: unsupported operand type(s) for /: 'Dimension' and 'int', please use // instead
```

Note that this PR does not change any current behavior, and have no impact with respect
to backward-compatible `__div__`. It merely adds additional notes in the error message.

Signed-off-by: default avatarYong Tang <yong.tang.github@outlook.com>
parent 130aebaa
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment