Merge Issue.pyi back to source (#2568)

Co-authored-by: Enrico Minack <github@enrico.minack.dev>
This commit is contained in:
Trim21
2023-07-07 11:43:29 +02:00
committed by GitHub
co-authored by Enrico Minack
parent 950a69493f
commit e306a3209b
3 changed files with 161 additions and 355 deletions
+10 -9
View File
@@ -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