Skip to content

mypy is unaware that displayio.Group supports the in operator #7948

@FoamyGuy

Description

@FoamyGuy

CircuitPython version

All

Code/REPL

my_group = displayio.Group()
# ... append some things ...
for item in my_group:
    print(item)

Behavior

mypy flags an error on code like this indicating that a value is unsupported for use in the right operand of the in operator:

error: Unsupported right operand type for in ("GridLayout")  [operator]

In this case GridLayout is extending Group. It flags the same issue whether its a subclass or the root class Group.

Description

No response

Additional information

Adding this in the stubs definition makes it so that mypy does not flag this as an error:

//|     def __contains__(
//|         self, item: Union[vectorio.Circle, vectorio.Rectangle, vectorio.Polygon, Group, TileGrid]
//|     ) -> bool: ...

I'll submit a PR with that addition to the comments that stubs come from. I tested locally by building stubs and installing with pip install .

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions