Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add typings of keys and values of __members__ dict #111

Closed
jasminlapalme opened this issue Aug 15, 2023 · 1 comment
Closed

Add typings of keys and values of __members__ dict #111

jasminlapalme opened this issue Aug 15, 2023 · 1 comment

Comments

@jasminlapalme
Copy link

It would be useful to add typings of the keys and values of the __members__ dictionary on class that represent enum in C.

For example, with this pybind11 code of library named lib :

py::enum_<Number>(m, "Number")
  .value("Zero", Number::Zero)
  .value("One", Number::One)
  .value("Tow", Number::Two);

instead of :

class Number():
  ....
  __members__: dict # value = {'Zero': <Number.Zero: 0>, 'One': < Number.One: 1>, 'Two': <Number.Two: 2>}

to have :

class Number():
  ....
  __members__: dict[str, lib.Number] # value = {'Zero': <Number.Zero: 0>, 'One': < Number.One: 1>, 'Two': <Number.Two: 2>}

When we import code with these kinds of stubs and use mypy to type checked the code, we have this warning.

error: Missing type parameters for generic type "dict"  [type-arg]
@sizmailov
Copy link
Owner

Thanks for the suggestion!

Implemented in #112

Example from tests:

__members__: typing.ClassVar[
typing.Dict[str, ConsoleForegroundColor]
] # value = {'Green': <ConsoleForegroundColor.Green: 32>, 'Yellow': <ConsoleForegroundColor.Yellow: 33>, 'Blue': <ConsoleForegroundColor.Blue: 34>, 'Magenta': <ConsoleForegroundColor.Magenta: 35>}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants