not following … I remember at some point there was a bug where are all enums were made available globally, but that was beyond them being available on the class name as well (I don’t recall further details; my brain is toast). That was for classes, not enum classes, though.
But specific to the example, the first code is not C++, the second code is not Python … so, could you send a specific, working, example that shows the problem?
Perhaps some answers will help already: MyEnum, the enum type, is represented as type int as that is how enums are represented (unsigned it would be better, but that doesn’t exist in Python). ‘MyEnum.Red’ should not work, as ‘Red’ is part of MyEnumClass. ‘Red’ lives at the namespace level as enum classes (a C++11 features) are not supported yet, so ‘MyEnumClass.Red’ would not currently work until an enum type is defined.
I have a bunch of e-mails from Danilo sitting and waiting for me to start tackling enums in ROOT6 (there’s quite a bit more to it). But have had zero time, unfortunately.
namespace ns
{
enum Color { Red, Green };
enum class Flavor : char { Up, Down }; // underlying type is char
enum class Orientation : long int { Down, Up };
};
void test();
mylib.cxx
#include "mylib.h"
void test()
{
ns::Color color = ns::Red;
ns::Flavor flavor = ns::Flavor::Up;
// this does not work:
// ns::Flavor flavor = ns::Up;
if (color == 0) { }
// this does not work:
// if (flavor == 0) { }
}
In [8]: ROOT.ns.Flavor.Up
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-8-d7bfea300838> in <module>()
----> 1 ROOT.ns.Flavor.Up
AttributeError: type object 'int' has no attribute 'Up'
bug 3
In [10]: ROOT.ns.Up
Out[10]: 1
in particular this not only is not correct from the namespace point of view, but it is also ambiguos (ns::Flavor::Up or ns::Orientation::Up)
bug 4
In [11]: ROOT.ns.Up == 1 # should be ROOT.ns.Flavor.Up
Out[11]: True
Personally I think for simplicity it is ok to cast all enum, or scoped enum to int in python. But the namespace issue should be corrected.