Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Literal and Protocol with runtime-referable symbols. #651

Merged
merged 2 commits into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 2 additions & 13 deletions comtypes/hints.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,11 @@
# - utilities for type hints.
import ctypes
import sys
from typing import Any as Any, ClassVar, Generic, NoReturn, TypeVar, overload
from typing import Any as Any, ClassVar, Generic, NoReturn, Protocol, TypeVar, overload
from typing import Optional, Union as _UnionT
from typing import List, Tuple as Tuple, Type
from typing import Tuple as Tuple, Type
from typing import Callable, Iterator, Sequence

if sys.version_info >= (3, 8):
from typing import Protocol
from typing import Literal as Literal
else:
from typing_extensions import Protocol
from typing_extensions import Literal as Literal
if sys.version_info >= (3, 9):
from typing import Annotated as Annotated
else:
Expand Down Expand Up @@ -85,11 +79,6 @@ class FirstComItfOf(Generic[_T_coclass]):
as an argument.
"""

class _MethodTypeDesc(Protocol):
arguments: List[Tuple[Any, str, List[str], Optional[Any]]]
idlflags: List[str]
name: str

_P_Put = ParamSpec("_P_Put")
_R_Put = TypeVar("_R_Put")
_P_PutRef = ParamSpec("_P_PutRef")
Expand Down
6 changes: 3 additions & 3 deletions comtypes/shelllink.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from ctypes import POINTER
from ctypes import byref, create_string_buffer, create_unicode_buffer
from ctypes.wintypes import DWORD, WIN32_FIND_DATAA, WIN32_FIND_DATAW, MAX_PATH
from typing import Tuple, TYPE_CHECKING
from typing import Tuple, TYPE_CHECKING, Literal

from comtypes import IUnknown, GUID, COMMETHOD, HRESULT, CoClass

Expand Down Expand Up @@ -143,7 +143,7 @@ def ShowCmd(self) -> int: ...
def ShowCmd(self, piShowCmd: int) -> None: ...
def SetIconLocation(self, pszIconPath: bytes, iIcon: int) -> hints.Hresult: ...
def SetRelativePath(
self, pszPathRel: bytes, dwReserved: hints.Literal[0]
self, pszPathRel: bytes, dwReserved: Literal[0]
) -> hints.Hresult: ...
def Resolve(self, hwnd: int, fFlags: int) -> hints.Hresult: ...
def SetPath(self, pszFile: bytes) -> hints.Hresult: ...
Expand Down Expand Up @@ -278,7 +278,7 @@ def ShowCmd(self) -> int: ...
def ShowCmd(self, piShowCmd: int) -> None: ...
def SetIconLocation(self, pszIconPath: str, iIcon: int) -> hints.Hresult: ...
def SetRelativePath(
self, pszPathRel: str, dwReserved: hints.Literal[0]
self, pszPathRel: str, dwReserved: Literal[0]
) -> hints.Hresult: ...
def Resolve(self, hwnd: int, fFlags: int) -> hints.Hresult: ...
def SetPath(self, pszFile: str) -> hints.Hresult: ...
Expand Down
14 changes: 7 additions & 7 deletions comtypes/tools/codegenerator/typeannotator.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import abc
import keyword
from typing import Any, Generic, TypeVar, TYPE_CHECKING
from typing import Any, Generic, Protocol, TypeVar
from typing import Dict, List, Optional, Sequence, Tuple
from typing import Iterable, Iterator

from comtypes.tools import typedesc

if TYPE_CHECKING:
from comtypes import hints

class _MethodTypeDesc(Protocol):
arguments: List[Tuple[Any, str, List[str], Optional[Any]]]
idlflags: List[str]
name: str

if TYPE_CHECKING:
_T_MTD = TypeVar("_T_MTD", bound=hints._MethodTypeDesc)
else:
_T_MTD = TypeVar("_T_MTD")

_T_MTD = TypeVar("_T_MTD", bound=_MethodTypeDesc)


class _MethodAnnotator(abc.ABC, Generic[_T_MTD]):
Expand Down