1. Team SimPy
  2. simpy
  3. simpy
  4. Pull requests

Pull requests

#11 Merged

Allow optional event names.

  1. luensdorf

Also restores normal str representation for events (except for processes). The id of events is very useful for debugging. If the user desires a custom string representation, he needs to supply a name.

Comments (7)

  1. Stefan Scherfke

    I propose the following str/repr representations:

    • Interrupt(Cause()) – essentially the same as for Exception, but with cause added
      • str: Interrupt(Cause)
      • repr: Interrupt(<Cause object at 0xbeef>)

    For event types, __str__ and __repr__ contain similar information. The former is a bit more concise while the latter uses the standard <Type object at 0xbeef> style. The env is ommited in all cases because it wouldn’t add valuable informatin.

    • Event(env)
      • str: Event()<0xbeef>
      • repr: <Event object at 0xbeef>
    • Event(env, name='Spam') – Providing a name for an Event (and its sub-classes) is a special case:
      • str: Spam
      • repr: <Event object "Spam" at 0xbeef>
    • Timeout(env, 3)
      • str: Timeout(3)<0xbeef>
      • repr: <Timeout(3) object at 0xbeef>
    • Timeout(env, 3, value=4)
      • str: Timeout(3, value=4)<0xbeef>
      • repr: <Timeout(3, value=4) object at 0xbeef>
    • Condition(env, all_events, Event(), Event())
      • str: Condition(all_events, <Event object at 0xdead>, <Event object at 0xc0de>)<0xbeef>)
      • repr: <Condition(all_events, <Event object at 0xdead>, <Event object at 0xc0de>) at 0xbeef>
    • Process(env, do_stuff())
      • str: Process(do_stuff)<0xbeef>
      • repr: <Process(do_stuff) object at 0xbeef>
    1. luensdorf author

      I still don't think it is necessary to override str and repr except if the user supplied a custom name, but as long as there's the id of the object visible in the default case, I'm happy. However dropping object at in the str case doesn't gain anything and may just confuse newbies. Lets stick to <{class}({args}) object at 0x{addr}> in both cases (which means we only need to override repr).