Skip to content

Commit

Permalink
v0.4.10: fix wrong enum typing
Browse files Browse the repository at this point in the history
  • Loading branch information
FindDefinition committed Nov 7, 2023
1 parent 04f000f commit 1cd215f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 6 additions & 4 deletions pccm/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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.
"""
Expand Down
12 changes: 8 additions & 4 deletions pccm/middlewares/pybind.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion pccm/stubs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import Literal, Optional, Union

import enum

class EnumClassValue(object):
def __init__(self, value: int):
Expand Down

0 comments on commit 1cd215f

Please sign in to comment.