diff --git a/CHANGELOG.md b/CHANGELOG.md index 0db34bb..054bbb5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ # Changelog +## [0.4.10] - 2023-11-07 +### Fixed +* fix wrong enum typing + ## [0.4.9] - 2023-10-17 ### Fixed * fix missing includes and alias when use impl-only dep with header only diff --git a/pccm/core/__init__.py b/pccm/core/__init__.py index 3e50f78..a2f46d7 100644 --- a/pccm/core/__init__.py +++ b/pccm/core/__init__.py @@ -813,7 +813,8 @@ def arg(self, type: str, default: Optional[str] = None, pyanno: Optional[str] = None, - array: Optional[Union[int, str]] = None): + array: Optional[Union[int, str]] = None, + doc: Optional[str] = None): """add a argument. """ type = str(type).strip() @@ -824,7 +825,7 @@ def arg(self, if not part.strip(): raise ValueError("you provide a empty name in", name) args.append( - Argument(part.strip(), type, default, pyanno=pyanno, array=array)) + Argument(part.strip(), type, default, pyanno=pyanno, array=array, doc=doc)) else: arg_attrs = arg_parser(name) for arg_with_attr in arg_attrs: @@ -835,7 +836,8 @@ def arg(self, type, default, pyanno=pyanno, - attrs=arg_with_attr.attrs, array=array)) + attrs=arg_with_attr.attrs, array=array, + doc=doc)) if type not in self._type_to_hook: hook = _get_attr_hook(type) if hook is not None: @@ -1051,7 +1053,7 @@ def __get_this_type(self): return cls_meta.python_inherit return getattr(self, PCCM_INIT_DECORATOR_KEY, None) - def set_this_class_type(self, this_cls_type: Type["Class"]): + def set_this_class_type(self, this_cls_type: Optional[Type["Class"]]): """get current Class Type during c++ constructing functions like add_member. """ diff --git a/pccm/middlewares/pybind.py b/pccm/middlewares/pybind.py index 734b76f..8ce6c97 100644 --- a/pccm/middlewares/pybind.py +++ b/pccm/middlewares/pybind.py @@ -922,15 +922,19 @@ class xxx: # Class EnumName: for ec in enum_classes: ec_items = [] # type: List[Union[Block, str]] + ec_enum_items = [] # type: List[Union[Block, str]] + enum_type = "EnumValue" if ec.scoped: enum_type = "EnumClassValue" - prefix = "class {}:".format(ec.name) + prefix = "class {}(enum.Enum):".format(ec.name) for key, value in ec.items: - ec_items.append("{k} = {ectype}({v}) # type: {ectype}".format( + ec_items.append("{k} = {clsname}.{k}".format( + k=key, v=value, clsname=ec.name)) + ec_enum_items.append("{k} = {v}".format( k=key, v=value, ectype=enum_type)) - def_items = ec_items.copy() + def_items = ec_enum_items.copy() def_items.append("@staticmethod") def_items.append( "def __members__() -> Dict[str, {}]: ...".format(enum_type)) @@ -1112,7 +1116,7 @@ class xxx: TODO insert docstring if exists """ init_import = "from typing import overload, Any, Callable, Dict, List, Optional, Set, Tuple, Type, Union" - init_pccm_import = "from pccm.stubs import EnumValue, EnumClassValue" + init_pccm_import = "from pccm.stubs import EnumValue, EnumClassValue, enum" ns_to_interfaces = OrderedDict() # type: Dict[str, List[Block]] ns_to_imports = OrderedDict() # type: Dict[str, List[str]] ns_to_interface = OrderedDict() # type: Dict[str, str] diff --git a/pccm/stubs/__init__.py b/pccm/stubs/__init__.py index 8229570..99720d6 100644 --- a/pccm/stubs/__init__.py +++ b/pccm/stubs/__init__.py @@ -1,5 +1,5 @@ from typing import Literal, Optional, Union - +import enum class EnumClassValue(object): def __init__(self, value: int):