Skip to content

[Pyright] Pyright complains in random_demo.py and average_total_reward.py #1269

@yjhan96

Description

@yjhan96

Describe the bug

When I run pre-commit run --all-files, I get the following error:

/home/albert-han/PettingZoo/pettingzoo/utils/average_total_reward.py
  /home/albert-han/PettingZoo/pettingzoo/utils/average_total_reward.py:37:40 - error: Argument of type "int | list[int] | list[list[int]] | list[list[list[Any]]]" cannot be assigned to parameter "seq" of type "SupportsLenAndGetItem[_T@choice]" in function "choice"
    Type "int | list[int] | list[list[int]] | list[list[list[Any]]]" cannot be assigned to type "SupportsLenAndGetItem[_T@choice]"
      "int" is incompatible with protocol "SupportsLenAndGetItem[_T@choice]"
        "__len__" is not present
        "__getitem__" is not present (reportGeneralTypeIssues)
/home/albert-han/PettingZoo/pettingzoo/utils/random_demo.py
  /home/albert-han/PettingZoo/pettingzoo/utils/random_demo.py:26:40 - error: Argument of type "int | list[int] | list[list[int]] | list[list[list[Any]]]" cannot be assigned to parameter "seq" of type "SupportsLenAndGetItem[_T@choice]" in function "choice"
    Type "int | list[int] | list[list[int]] | list[list[list[Any]]]" cannot be assigned to type "SupportsLenAndGetItem[_T@choice]"
      "int" is incompatible with protocol "SupportsLenAndGetItem[_T@choice]"
        "__len__" is not present
        "__getitem__" is not present (reportGe

These pyright errors seem valid to me as tolist()'s return type includes a scalar, and random.choice() doesn't accept scalar values as arguments.

Code example

Following line causes a pyright error:

action = random.choice(np.flatnonzero(obs["action_mask"]).tolist())

System info

No response

Additional context

No response

Checklist

  • I have checked that there is no similar issue in the repo

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions