mirror of
https://github.com/status-im/PyGithub.git
synced 2026-08-31 19:01:15 +00:00
Merge Issue.pyi back to source (#2568)
Co-authored-by: Enrico Minack <github@enrico.minack.dev>
This commit is contained in:
+10
-9
@@ -46,15 +46,15 @@ from typing import (
|
||||
Any,
|
||||
Callable,
|
||||
Dict,
|
||||
Generic,
|
||||
List,
|
||||
Optional,
|
||||
Tuple,
|
||||
Type,
|
||||
Union,
|
||||
)
|
||||
|
||||
from dateutil import parser
|
||||
from typing_extensions import TypeGuard
|
||||
from typing_extensions import Protocol, TypeGuard
|
||||
|
||||
from . import Consts
|
||||
from .GithubException import BadAttributeException, IncompletableObject
|
||||
@@ -63,15 +63,16 @@ if TYPE_CHECKING:
|
||||
from .Requester import Requester
|
||||
|
||||
T = typing.TypeVar("T")
|
||||
T_co = typing.TypeVar("T_co", covariant=True)
|
||||
|
||||
|
||||
class Attribute(Generic[T]):
|
||||
class Attribute(Protocol[T_co]):
|
||||
@property
|
||||
def value(self) -> T:
|
||||
def value(self) -> T_co:
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
class _NotSetType(Attribute):
|
||||
class _NotSetType:
|
||||
def __repr__(self):
|
||||
return "NotSet"
|
||||
|
||||
@@ -97,15 +98,15 @@ def is_defined(v: Union[T, _NotSetType]) -> TypeGuard[T]:
|
||||
return not isinstance(v, _NotSetType)
|
||||
|
||||
|
||||
def is_undefined(v: Any) -> TypeGuard[_NotSetType]:
|
||||
def is_undefined(v: Union[T, _NotSetType]) -> TypeGuard[_NotSetType]:
|
||||
return isinstance(v, _NotSetType)
|
||||
|
||||
|
||||
def is_optional(v, type: Type[T]) -> TypeGuard[Opt[T]]:
|
||||
def is_optional(v, type: Union[Type, Tuple[Type, ...]]) -> bool:
|
||||
return isinstance(v, _NotSetType) or isinstance(v, type)
|
||||
|
||||
|
||||
def is_optional_list(v, type: Type[T]) -> TypeGuard[Opt[List[T]]]:
|
||||
def is_optional_list(v, type: Union[Type, Tuple[Type, ...]]) -> bool:
|
||||
return (
|
||||
isinstance(v, _NotSetType)
|
||||
or isinstance(v, list)
|
||||
@@ -113,7 +114,7 @@ def is_optional_list(v, type: Type[T]) -> TypeGuard[Opt[List[T]]]:
|
||||
)
|
||||
|
||||
|
||||
class _ValuedAttribute(Attribute, Generic[T]):
|
||||
class _ValuedAttribute(Attribute[T]):
|
||||
def __init__(self, value: T):
|
||||
self._value = value
|
||||
|
||||
|
||||
Reference in New Issue
Block a user