Comments (9)
AHHHH I am such an idiot, the enums are all under a namespace. If I import the namespace then all the enums show up.
Man thank you so much for the help @wlav and thank you again for this package.
from cppyy.
Not really sure that I understand the question ... a "header file" isn't a coherent unit as seen by the compiler (certainly not something that persists). Would if they all live in the same namespace, though. Otherwise, any such approach simply identifies all enums seen so far, including ones you may not be interested in.
Specific to the given code, __dict__
is just a place to cache results that have been found. The way to browse contents of a scope would be to use dir()
, ie. dir(cppyy.gbl)
and then use getattr
. However, enums could be anonymous, in which case they won't appear as a type at all in dir()
(nor, eventually, __dict__
), only their values; or they could be different types, in which case they need not derive from int
.
from cppyy.
When I try to read dir(cppyy.gbl)
the enums don't show up in the list. Only if I manually call from cppyy.gbl import Enum1, Enum2
then they show up.
But I would like to avoid calling 30 imports for the 30 enums that exist in my file. The enums in my file are not anonymous and each have a specific name like Enum1, Enum2, etc....
from cppyy.
Can you post the file so that I can reproduce? A basic enum.h
like so:
enum A { a, b };
shows that enum just fine:
>>> import cppyy
>>> cppyy.include("enum.h")
True
>>> dir(cppyy.gbl)
['A', ...
>>>
from cppyy.
I cannot post the full file but here is a portion to give you an idea. There are about 30 or so enums in the file and all have the same syntax as below, just different names and values:
enum DebugTypeEnum {
DebugTypeEnum_UnknownDebugType = 0,
DebugTypeEnum_LOG_EMERG = 1,
DebugTypeEnum_LOG_ALERT = 2,
DebugTypeEnum_LOG_CRIT = 3,
DebugTypeEnum_LOG_ERR = 4,
DebugTypeEnum_LOG_WARNING = 5,
DebugTypeEnum_LOG_NOTICE = 6,
DebugTypeEnum_LOG_INFO = 7,
DebugTypeEnum_LOG_DEBUG = 8,
DebugTypeEnum_LOG_DEVICE = 9,
DebugTypeEnum_MIN = DebugTypeEnum_UnknownDebugType,
DebugTypeEnum_MAX = DebugTypeEnum_LOG_DEVICE
};
inline const DebugTypeEnum (&EnumValuesDebugTypeEnum())[10] {
static const DebugTypeEnum values[] = {
DebugTypeEnum_UnknownDebugType,
DebugTypeEnum_LOG_EMERG,
DebugTypeEnum_LOG_ALERT,
DebugTypeEnum_LOG_CRIT,
DebugTypeEnum_LOG_ERR,
DebugTypeEnum_LOG_WARNING,
DebugTypeEnum_LOG_NOTICE,
DebugTypeEnum_LOG_INFO,
DebugTypeEnum_LOG_DEBUG,
DebugTypeEnum_LOG_DEVICE
};
return values;
}
inline const char * const *EnumNamesDebugTypeEnum() {
static const char * const names[] = {
"UnknownDebugType",
"LOG_EMERG",
"LOG_ALERT",
"LOG_CRIT",
"LOG_ERR",
"LOG_WARNING",
"LOG_NOTICE",
"LOG_INFO",
"LOG_DEBUG",
"LOG_DEVICE",
nullptr
};
return names;
}
inline const char *EnumNameDebugTypeEnum(DebugTypeEnum e) {
if (e < DebugTypeEnum_UnknownDebugType || e > DebugTypeEnum_LOG_DEVICE) return "";
const size_t index = static_cast<size_t>(e);
return EnumNamesDebugTypeEnum()[index];
}
from cppyy.
It does show up for me:
>>> dir(cppyy.gbl)
['CppyyLegacy', 'DebugTypeEnum', ...
>>> dir(cppyy.gbl.DebugTypeEnum)
['DebugTypeEnum_LOG_ALERT', 'DebugTypeEnum_LOG_CRIT', ...
If it doesn't give you the same result, what version/platform are we speaking here?
from cppyy.
cppyy==3.0.0
cppyy-backend==1.14.11
cppyy-cling==6.28.0
But I don't think it has to do with the version. The C++ project I am dealing with is quite large and I have many other include paths involved besides just the enums.h file.
from cppyy.
Closed by mistake, Here is my dir output...
>>> import cppyy
>>> cppyy.include("path_to_folder/enums.h")
True
>>> dir(cppyy.gbl)
['CppyyLegacy', '__add__', '__bool__', '__class__', '__delattr__', '__destruct__', '__dict__', '__dir__', '__dispatch__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__invert__', '__le__', '__lt__', '__module__', '__mul__', '__ne__', '__neg__', '__new__', '__pos__', '__python_owns__', '__radd__', '__reduce__', '__reduce_ex__', '__repr__', '__reshape__', '__rmul__', '__rsub__', '__rtruediv__', '__setattr__', '__sizeof__', '__smartptr__', '__str__', '__sub__', '__subclasshook__', '__truediv__', '__weakref__', 'int8_t', 'std', 'uint8_t']
from cppyy.
Interesting, so I created my own local test-enums.h with a single enum and that showed up in dir. So then I made a copy of my enums.h and moved it over to my python project repository, but dir() of that local enums.h is not showing the enums still...
Is there a limit to what dir() can show? Maybe there are too many enums for it to show?
from cppyy.
Related Issues (20)
- Not working on Windows HOT 10
- Special variables are missing with pypy
- Segfault during garbage collection HOT 1
- Segfault when class owns a unique_ptr HOT 1
- Enums are not correctly resolved when using an alias within a class/struct HOT 2
- Read/write past end of object of an enum type declared via a type alias if size is less than 4 bytes HOT 4
- Manually specifying the `-march` compiler flag HOT 2
- Conversion operator seems not to be working HOT 1
- How about this code? HOT 1
- Change of behavior of heuristic memory policy
- Setting any member from Python for a C++ class HOT 1
- cppyy/test: make all build command fails HOT 6
- Implicit conversion to `unique_ptr` hijacks overload resolution. HOT 3
- Deprecation warning when importing `cppyy` in unit tests
- Leaks with cppyy==3.1.2 HOT 4
- Importing cppyy before xgboost breaks xgboost HOT 1
- Statefulness of converters is not considered over multiple function calls HOT 2
- `TypeError` instead of common exception type for overloaded functions HOT 1
- Macro redefined '__CLING__GNUC__' warning while running sample CUDA code HOT 2
- Should assert() work? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cppyy.