ipython/ipython — Issue #942: number traits should cast if value doesn't change
Author: minrk
Created: 2011-10-29 19:14:35+00:00
State: open
Labels: prio-high, quickfix, status-active, type-enhancement

The most common trait error I see is integers failing because they were passed a long, thanks to json or some such.

The non-casting number traits should try casting, and if the value does not change let it go.

So if you have:

```python

class C(HasTraits):
a = Int()
b = Float()
```

The following should work:

```python

c = C()
c.a = 4
c.a = 4L
c.a = 4.0
c.b = 4
c.b = 4L
c.b = 4.0
```
But still prevent the following:

```python

c = C()
c.a = 4444444444444444444444444444444444444444444444L
c.a = 4.1
```

I'm less concerned about float <=> int conversion, but the long/int conversion should really be allowed, as it happens a lot and is usually due to annoying behavior in libraries that don't support multiple integer types.

This would break traits compatibility, which also has this unpleasant behavior. If we want to preserve traits compat, then we should just replace *all* Int/Long instances with their casting counterparts, because this gets annoying.