Skip to content

More dictionary methods for AthConfigFlags

Dan Guest requested to merge dguest/athena:flags into main

The changes I made in !64979 (merged) left a few uncomfortable loose ends:

  • I defined __getitem__ but no __setitem__
  • The asdict() only works for a subset of the flags, i.e. flags.A.asdict() works but flags.asdict() fails
  • Iterating over the flags is only possible via
    for key in flags.A.asdict():
        do_something(key)
    which is kind of ugly and confusing

I fixed all these issues and added corresponding unit tests. One ugly thing I found, while testing this in some real AthAnalysis code, is that trying to convert all the flags to a dict will throw a lot of ModuleNotFound. For lack of a better idea I'm catching this exception in the top level asdict() function.

Might be interesting to @khoo

Goals:

  • Add __setitem__ for flags
  • Extend asdict() to cover AthConfigFlags, not just FlagAddress
  • Support iterators, which behave like nested dictionary iterators (key iteration over the direct children)
  • Test in a complete setup
Edited by Dan Guest

Merge request reports