diff --git a/src/io_scene_vrm/common/convert_any.py b/src/io_scene_vrm/common/convert_any.py index 629afa2c7..72d6d2028 100644 --- a/src/io_scene_vrm/common/convert_any.py +++ b/src/io_scene_vrm/common/convert_any.py @@ -1,30 +1,28 @@ -"""Any型や、Any型を型引数に持つの変数のAny部分をobjectとして読み直す関数を提供する. +"""A module provides a function to convert a variable of type Any to a concrete type. -どうしてもAny型の変数が発生することがあり、そのような変数はmypyやpyrightはそのまま扱うことができない。 -公式にはcastを使ってどうにかするっぽいが、castは使い始めると収拾がつかなくなる。 -そのため、このモジュールでのみ例外的にAnyを許可し、objectに変換することで利用可能な変数に変換する。 - -pyrightでUnknownをobject扱いするIssueが出ている。 -https://github.com/microsoft/pyright/issues/3650 +Inevitably, variables of type Any may occur, and such variables cannot be handled +in mypy or pyright in strict mode. Any is allowed only in the module here. """ from collections.abc import Iterator from typing import ( - Any, # Anyはここのモジュールのみで利用を許可する。 + Any, # Any is allowed only in the module here. Optional, ) def to_object( # type: ignore[misc] - any_object: Any, # noqa: ANN401 # Anyはここのモジュールのみで利用を許可する。 + any_object: Any, # noqa: ANN401 # Any is allowed only in the module here. ) -> object: + # Interpret Unknown as object + # https://github.com/microsoft/pyright/issues/3650 if not isinstance(any_object, object): raise TypeError # typing.assert_never() return any_object def iterator_to_object_iterator( # type: ignore[misc] - any_iterator: Any, # noqa: ANN401 # Anyはここのモジュールのみで利用を許可する。 + any_iterator: Any, # noqa: ANN401 # Any is allowed only in the module here. ) -> Optional[Iterator[object]]: any_iterator_without_type_narrowing = any_iterator if not isinstance(any_iterator_without_type_narrowing, Iterator):