mikedh / trimesh

Python library for loading and using triangular meshes.
https://trimesh.org
MIT License
3.02k stars 583 forks source link

Type Hint Issues: Pyright + Mypy #2192

Open mikedh opened 8 months ago

mikedh commented 8 months ago

It would be a "nice to have" to someday pass pyright. We currently pass all unit tests using beartype or typeguard as of #2188 so type hints reflect the values passed in unit tests. I'd like to keep type hint stuff contained to this issue to avoid being overwhelmed, and any PR's fixing any of these are very welcome! Currently:

mikedh@orion:trimesh$ pyright trimesh
...
1120 errors, 3 warnings, 0 informations

If anyone is interested in contributing a great place to start would be fixing a single file, i.e.:

mikedh@orion:trimesh$ pyright trimesh/sample.py
/home/mikedh/trimesh/trimesh/sample.py
  /home/mikedh/trimesh/trimesh/sample.py:62:18 - error: No overloads for "cumsum" match the provided arguments (reportCallIssue)
  /home/mikedh/trimesh/trimesh/sample.py:62:28 - error: Argument of type "ArrayLike | Unknown | None" cannot be assigned to parameter "a" of type "ArrayLike" in function "cumsum" (reportArgumentType)
  /home/mikedh/trimesh/trimesh/sample.py:112:33 - error: "uv_vectors" is possibly unbound (reportPossiblyUnboundVariable)
  /home/mikedh/trimesh/trimesh/sample.py:113:45 - error: "uv_origins" is possibly unbound (reportPossiblyUnboundVariable)
  /home/mikedh/trimesh/trimesh/sample.py:211:5 - error: Expression with type "tuple[Unknown, Unknown, Unknown | None] | tuple[Unknown, Unknown]" cannot be assigned to target tuple
    Type "tuple[Unknown, Unknown, Unknown | None]" is incompatible with target tuple
      Tuple size mismatch; expected 2 but received 3 (reportAssignmentType)
5 errors, 0 warnings, 0 informations
mikedh commented 2 months ago

Hey @wenbc21 I've been tweaking the types when it affects me but there's no major effort on these. Beartype catches egregious violations in tests, but mypy/pylance would still need quite a bit of work. PR's would be great!