Skip to content

Commit

Permalink
stubs: Utilize typing.type_check_only
Browse files Browse the repository at this point in the history
  • Loading branch information
WMOkiishi committed Jan 23, 2024
1 parent 382b4c9 commit 3c3088f
Show file tree
Hide file tree
Showing 21 changed files with 198 additions and 107 deletions.
2 changes: 1 addition & 1 deletion idbstubs/processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def process_class(class_: Class) -> None:
class_body['__iter__'] = Function(
'__iter__',
[Signature([Parameter('self')], iter_return_type)],
comment="Doesn't actually exist",
type_check_only=True,
)
class_.body = class_body
if PTA_NAME_REGEX.match(class_.name):
Expand Down
5 changes: 5 additions & 0 deletions idbstubs/reps.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ class Function(StubRep):
name: str
signatures: Sequence[Signature] = field(converter=tuple)
is_static_method: bool = field(default=False, kw_only=True)
type_check_only: bool = field(default=False, kw_only=True)
comment: str = field(default='', kw_only=True, eq=False)

def __str__(self) -> str:
Expand All @@ -203,6 +204,8 @@ def __str__(self) -> str:
def get_dependencies(self) -> Iterator[str]:
if len(self.signatures) > 1:
yield 'overload'
if self.type_check_only:
yield 'type_check_only'
for signature in self.signatures:
yield from signature.get_dependencies()

Expand All @@ -212,6 +215,8 @@ def definition(self, *, indent_level: int = 0) -> Iterator[str]:
decorators.append('overload')
if self.is_static_method:
decorators.append('staticmethod')
if self.type_check_only:
decorators.append('type_check_only')
comment_needed = bool(self.comment)
for signature in self.signatures:
definition_lines = signature.definition(
Expand Down
1 change: 1 addition & 0 deletions idbstubs/typedata.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
'NoReturn': 'typing',
'overload': 'typing',
'Self': 'typing_extensions', # Introduced in 3.11
'type_check_only': 'typing',
'TypeAlias': 'typing_extensions', # Introduced in 3.10
'TypeVar': 'typing',
'StrOrBytesPath': '_typeshed',
Expand Down
3 changes: 2 additions & 1 deletion src/direct-stubs/showbase/PythonUtil.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from _typeshed import SupportsWrite
from collections.abc import Callable, Collection, Container, Generator, Iterable, Mapping, MutableSequence, Sequence
from typing import Any, ClassVar, Generic, TextIO, TypeVar, overload
from typing import Any, ClassVar, Generic, TextIO, TypeVar, overload, type_check_only
from typing_extensions import Never, Self, TypeAlias

from direct._typing import AnyReal
Expand Down Expand Up @@ -171,6 +171,7 @@ def appendStr(obj: _T, st: str) -> _T: ...

class ScratchPad(Generic[_T]):
def __init__(self, **kArgs: _T) -> None: ...
@type_check_only
def __getattr__(self, name: str) -> _T: ...
def __setattr__(self, name: str, value: _T) -> None: ...
def add(self, **kArgs: _T) -> None: ...
Expand Down
3 changes: 2 additions & 1 deletion src/direct-stubs/stdpy/threading.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ __all__ = [
]

from collections.abc import Callable, Iterable, Mapping
from typing import Any, Final, NoReturn
from typing import Any, Final, NoReturn, type_check_only
from typing_extensions import Never

from direct._typing import Unused
Expand All @@ -33,6 +33,7 @@ TIMEOUT_MAX: Final[float]
class local:
def __del__(self) -> None: ...
def __setattr__(self, key: str, value: Any) -> None: ...
@type_check_only
def __getattr__(self, key: str) -> Any: ...

class ThreadBase:
Expand Down
5 changes: 3 additions & 2 deletions src/panda3d-stubs/core/_device.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from collections.abc import Iterator, Sequence
from enum import Enum
from typing import Any, ClassVar, Final, Literal, overload
from typing import Any, ClassVar, Final, Literal, overload, type_check_only
from typing_extensions import Self, TypeAlias

from panda3d.core._dgraph import DataNode
Expand Down Expand Up @@ -462,7 +462,8 @@ class InputDeviceSet:
"""Returns the number of devices in the collection."""
def __copy__(self) -> Self: ...
def __deepcopy__(self, memo: object, /) -> Self: ...
def __iter__(self) -> Iterator[InputDevice]: ... # Doesn't actually exist
@type_check_only
def __iter__(self) -> Iterator[InputDevice]: ...
def assign(self, copy: Self) -> Self: ...
def clear(self) -> None:
"""Removes all InputDevices from the collection."""
Expand Down
5 changes: 3 additions & 2 deletions src/panda3d-stubs/core/_downloader.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from _typeshed import StrOrBytesPath
from collections.abc import Iterator
from typing import Any, ClassVar, Final, Literal, overload
from typing import Any, ClassVar, Final, Literal, overload, type_check_only
from typing_extensions import Self, TypeAlias

from panda3d._typing import URL
Expand Down Expand Up @@ -205,7 +205,8 @@ class URLSpec:
def __getitem__(self, n: int) -> str: ...
def __copy__(self) -> Self: ...
def __deepcopy__(self, memo: object, /) -> Self: ...
def __iter__(self) -> Iterator[str]: ... # Doesn't actually exist
@type_check_only
def __iter__(self) -> Iterator[str]: ...
def assign(self, url: str) -> Self: ...
def compare_to(self, other: URL) -> int:
"""Returns a number less than zero if this URLSpec sorts before the other one,
Expand Down
5 changes: 3 additions & 2 deletions src/panda3d-stubs/core/_dtoolutil.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from _typeshed import StrOrBytesPath
from collections.abc import Iterator, MutableMapping, Sequence
from typing import Any, ClassVar, Final, Literal, overload
from typing import Any, ClassVar, Final, Literal, overload, type_check_only
from typing_extensions import Self, TypeAlias

from panda3d._typing import SearchPathLike
Expand Down Expand Up @@ -1242,7 +1242,8 @@ class DSearchPath:
"""
def __copy__(self) -> Self: ...
def __deepcopy__(self, memo: object, /) -> Self: ...
def __iter__(self) -> Iterator[Filename]: ... # Doesn't actually exist
@type_check_only
def __iter__(self) -> Iterator[Filename]: ...
def assign(self, copy: DSearchPath.Results) -> Self: ...
def clear(self) -> None:
"""Removes all the files from the list."""
Expand Down
5 changes: 3 additions & 2 deletions src/panda3d-stubs/core/_event.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from collections.abc import Callable, Generator, Iterator, Sequence
from typing import Any, ClassVar, Final, Literal, final, overload
from typing import Any, ClassVar, Final, Literal, final, overload, type_check_only
from typing_extensions import Self, TypeAlias, deprecated

from panda3d._typing import TaskCoroutine, TaskFunction
Expand Down Expand Up @@ -642,7 +642,8 @@ class AsyncTaskCollection:
def __add__(self, other: AsyncTaskCollection) -> AsyncTaskCollection: ...
def __copy__(self) -> Self: ...
def __deepcopy__(self, memo: object, /) -> Self: ...
def __iter__(self) -> Iterator[AsyncTask]: ... # Doesn't actually exist
@type_check_only
def __iter__(self) -> Iterator[AsyncTask]: ...
def assign(self, copy: Self) -> Self: ...
def add_task(self, task: AsyncTask) -> None:
"""Adds a new AsyncTask to the collection."""
Expand Down
29 changes: 19 additions & 10 deletions src/panda3d-stubs/core/_express.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys
from _typeshed import StrOrBytesPath
from collections.abc import Iterator, Sequence
from typing import Any, ClassVar, Final, Literal, overload
from typing import Any, ClassVar, Final, Literal, overload, type_check_only
from typing_extensions import Self, TypeAlias

from panda3d._typing import SearchPathLike
Expand Down Expand Up @@ -122,7 +122,8 @@ class ConstPointerToArray_double(PointerToArrayBase_double):
def __getitem__(self, n: int) -> float: ...
def __deepcopy__(self, memo, /) -> ConstPointerToArray_double: ...
def __copy__(self) -> Self: ...
def __iter__(self) -> Iterator[float]: ... # Doesn't actually exist
@type_check_only
def __iter__(self) -> Iterator[float]: ...
def get_element(self, n: int) -> float: ...
def get_data(self) -> bytes: ...
def get_subdata(self, n: int, count: int) -> bytes: ...
Expand Down Expand Up @@ -150,7 +151,8 @@ class ConstPointerToArray_float(PointerToArrayBase_float):
def __getitem__(self, n: int) -> float: ...
def __deepcopy__(self, memo, /) -> ConstPointerToArray_float: ...
def __copy__(self) -> Self: ...
def __iter__(self) -> Iterator[float]: ... # Doesn't actually exist
@type_check_only
def __iter__(self) -> Iterator[float]: ...
def get_element(self, n: int) -> float: ...
def get_data(self) -> bytes: ...
def get_subdata(self, n: int, count: int) -> bytes: ...
Expand Down Expand Up @@ -178,7 +180,8 @@ class ConstPointerToArray_int(PointerToArrayBase_int):
def __getitem__(self, n: int) -> int: ...
def __deepcopy__(self, memo, /) -> ConstPointerToArray_int: ...
def __copy__(self) -> Self: ...
def __iter__(self) -> Iterator[int]: ... # Doesn't actually exist
@type_check_only
def __iter__(self) -> Iterator[int]: ...
def get_element(self, n: int) -> int: ...
def get_data(self) -> bytes: ...
def get_subdata(self, n: int, count: int) -> bytes: ...
Expand Down Expand Up @@ -206,7 +209,8 @@ class ConstPointerToArray_unsigned_char(PointerToArrayBase_unsigned_char):
def __getitem__(self, n: int) -> int: ...
def __deepcopy__(self, memo, /) -> ConstPointerToArray_unsigned_char: ...
def __copy__(self) -> Self: ...
def __iter__(self) -> Iterator[int]: ... # Doesn't actually exist
@type_check_only
def __iter__(self) -> Iterator[int]: ...
def get_element(self, n: int) -> int: ...
def get_data(self) -> bytes: ...
def get_subdata(self, n: int, count: int) -> bytes: ...
Expand All @@ -231,7 +235,8 @@ class PointerToArray_double(PointerToArrayBase_double):
def __setitem__(self, n: int, value: float) -> None: ...
def __deepcopy__(self, memo, /) -> PointerToArray_double: ...
def __copy__(self) -> Self: ...
def __iter__(self) -> Iterator[float]: ... # Doesn't actually exist
@type_check_only
def __iter__(self) -> Iterator[float]: ...
@staticmethod
def empty_array(n: int, type_handle: TypeHandle | type = ...) -> PointerToArray_double: ...
def push_back(self, x: float) -> None: ...
Expand Down Expand Up @@ -269,7 +274,8 @@ class PointerToArray_float(PointerToArrayBase_float):
def __setitem__(self, n: int, value: float) -> None: ...
def __deepcopy__(self, memo, /) -> PointerToArray_float: ...
def __copy__(self) -> Self: ...
def __iter__(self) -> Iterator[float]: ... # Doesn't actually exist
@type_check_only
def __iter__(self) -> Iterator[float]: ...
@staticmethod
def empty_array(n: int, type_handle: TypeHandle | type = ...) -> PointerToArray_float: ...
def push_back(self, x: float) -> None: ...
Expand Down Expand Up @@ -307,7 +313,8 @@ class PointerToArray_int(PointerToArrayBase_int):
def __setitem__(self, n: int, value: int) -> None: ...
def __deepcopy__(self, memo, /) -> PointerToArray_int: ...
def __copy__(self) -> Self: ...
def __iter__(self) -> Iterator[int]: ... # Doesn't actually exist
@type_check_only
def __iter__(self) -> Iterator[int]: ...
@staticmethod
def empty_array(n: int, type_handle: TypeHandle | type = ...) -> PointerToArray_int: ...
def push_back(self, x: int) -> None: ...
Expand Down Expand Up @@ -345,7 +352,8 @@ class PointerToArray_unsigned_char(PointerToArrayBase_unsigned_char):
def __setitem__(self, n: int, value: int) -> None: ...
def __deepcopy__(self, memo, /) -> PointerToArray_unsigned_char: ...
def __copy__(self) -> Self: ...
def __iter__(self) -> Iterator[int]: ... # Doesn't actually exist
@type_check_only
def __iter__(self) -> Iterator[int]: ...
@staticmethod
def empty_array(n: int, type_handle: TypeHandle | type = ...) -> PointerToArray_unsigned_char: ...
def push_back(self, x: int) -> None: ...
Expand Down Expand Up @@ -2412,7 +2420,8 @@ class VirtualFileList(ReferenceCount):
def __add__(self, other: VirtualFileList) -> VirtualFileList: ...
def __copy__(self) -> Self: ...
def __deepcopy__(self, memo: object, /) -> Self: ...
def __iter__(self) -> Iterator[VirtualFile]: ... # Doesn't actually exist
@type_check_only
def __iter__(self) -> Iterator[VirtualFile]: ...
def get_num_files(self) -> int:
"""Returns the number of files in the list."""
def get_file(self, n: int) -> VirtualFile:
Expand Down
5 changes: 3 additions & 2 deletions src/panda3d-stubs/core/_gobj.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from _typeshed import StrOrBytesPath
from collections.abc import Iterator, Mapping, MutableMapping, MutableSequence, Sequence
from typing import Any, ClassVar, Final, Literal, final, overload
from typing import Any, ClassVar, Final, Literal, final, overload, type_check_only
from typing_extensions import Self, TypeAlias, deprecated

from panda3d._typing import (
Expand Down Expand Up @@ -10241,7 +10241,8 @@ class TextureCollection:
def __add__(self, other: TextureCollection) -> TextureCollection: ...
def __copy__(self) -> Self: ...
def __deepcopy__(self, memo: object, /) -> Self: ...
def __iter__(self) -> Iterator[Texture]: ... # Doesn't actually exist
@type_check_only
def __iter__(self) -> Iterator[Texture]: ...
def assign(self, copy: Self) -> Self: ...
def add_texture(self, texture: Texture) -> None:
"""Adds a new Texture to the collection."""
Expand Down

0 comments on commit 3c3088f

Please sign in to comment.