Adjusting from_string to Recognize Sub-classes of Built-in Types

12 views
Skip to first unread message

Thomas Macrina

unread,
Apr 15, 2014, 2:26:10 PM4/15/14
to deap-...@googlegroups.com
Hey guys,

I messaged the deap-developers list with this problem a few weeks back. I found that from_string doesn't recognize terminals that are subclasses of built-in types. Here's the fix that I found works for me (builds off v1.0.1 with the patch from issue #32): https://gist.github.com/macrintr/9877164 (see line 72)

Here's an example case: I have two terminal types - "large_int", "small_int" - that are subclasses of "int". In string form, those two terminals will just be ints. When evaluated in from_string, those terminals will be typed will be as "int". But my pset only has terminals for "large_int" or "small_int" types, so from_string will fail. But if I check for subclasses, my pset terminal types will be accepted as viable options.

Let me know if you can think of other situations where that solution might fail. Thanks again, guys.

Thomas
Reply all
Reply to author
Forward
0 new messages