Skip to content

Commit

Permalink
docs: comment translation
Browse files Browse the repository at this point in the history
  • Loading branch information
saturday06 committed Jun 17, 2024
1 parent 921f2b2 commit eb64382
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/io_scene_vrm/common/convert_any.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down

0 comments on commit eb64382

Please sign in to comment.