Closed jason-s closed 9 years ago
hmm... it looks like IntValidator
will work on long
s, but its minimum
and maximum
fields are strictly int
. Would it be more appropriate to create an IntegerValidator which replaces minimum
and maximum
with Typed(long)
and is clearly designed for integers in general rather than int
or long
?
https://github.com/nucleic/enaml/blob/master/enaml/validator.py
this appears to work... one of these days I will learn how to do git pull requests :/
enamldef LongField(Field):
""" A field that only accepts integer inputs.
"""
attr minimum = None
attr maximum = None
attr base = 10
attr value : long = 0
attr converter << enaml.stdlib.fields._int_converters.get(base, unicode)
text << converter(value)
text :: self.value = long(text, base)
validator << IntValidator(base=base, minimum=minimum, maximum=maximum)
This should handle ints and longs:
from numbers import Integral
class IntegralValidator(IntValidator):
minimum = Instance(Integral)
maximum = Instance(Integral)
enamldef IntegralField(IntField):
attr value: Integral = 0
validator << IntegralValidator(base=base, minimum=minimum, maximum=maximum)
Oh, that's much simpler. Thanks! Is this something you could add to a future enaml release?
I'm holding off on new features for now, until we hit Atom 1.0 and we get an idea of where we to take the project.
sounds good, it's an easy workaround. Perhaps a note in the IntField
docs linking to this issue would be appropriate? The error message threw me a real curveball until I started poking around in the source. (UTSL is good when you have the time + understanding to learn, not so good when things get panicky)
I'm working with unsigned 32-bit integers, which won't fit in an
int
, so I need to use anatom.api.Long
rather than anatom.api.Int
, but thenIntField
won't work. But there is noLongField
orLongValidator
:/This gist https://gist.github.com/jason-s/5f884e80ffd8a7c15af7 fails with
TypeError: invalid instance type
when I use enaml-run.