Skip to content

Commit

Permalink
implement Dummy
Browse files Browse the repository at this point in the history
  • Loading branch information
ShineyDev committed Jan 23, 2025
1 parent cb883cc commit f7babad
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 0 deletions.
3 changes: 3 additions & 0 deletions github/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
from github.core.client import *
from github.core.client import __all__ as _client__all__
from github.core.dummy import *
from github.core.dummy import __all__ as _dummy__all__
from github.core.errors import *
from github.core.errors import __all__ as _errors__all__


__all__: list[str] = [ # type: ignore[reportUnsupportedDunderAll]
*_client__all__,
*_dummy__all__,
*_errors__all__,
]
120 changes: 120 additions & 0 deletions github/core/dummy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
from __future__ import annotations
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import cast

from github.core import Client
from github.core.http import HTTPClient
from github.interfaces import Type

import github
from github.utility import MISSING


if TYPE_CHECKING:
from typing import Any
else:
Any = object


class Dummy(Any):
"""
A lightweight stand-in for GitHub objects.
Parameters
----------
client: :class:`~github.Client`
Your client. Provide this only when the dummy is acting as a
stand-in for the "self" parameter of an unbound method.
id: :class:`str`
An :attr:`object identifier <github.Node.id>`.
type: :class:`~github.Type`
An object type. This doesn't have a use yet.
Example
-------
.. code-block:: python
label = github.Dummy(id="LA_kwCqcmVwb3NpdG9yeaVsYWJlbA")
pull = github.Dummy(client=client, id="PR_kwCqcmVwb3NpdG9yeaRwdWxs")
await github.Pull.remove_labels(pull, label)
"""

def __init__(
self,
/,
*,
client: Client = MISSING,
id: str = MISSING,
type: Type = MISSING,
) -> None:
self._client: Client = client
self._id: str = id
self._type: Type = type

@property
def _data(self, /) -> dict[Any, Any]:
return DummyData()

@property
def _graphql_fields(self, /) -> dict[str, str] | list[str]:
if self._type is MISSING:
raise AttributeError

return self._type._graphql_fields

@property
def _graphql_type(self, /) -> str:
if self._type is MISSING:
raise AttributeError

return self._type._graphql_type

@property
def _http(self, /) -> HTTPClient:
if self._client is MISSING:
raise AttributeError

return self._client._http

@property
def _node_prefix(self, /) -> str:
if self._type is MISSING:
raise AttributeError

if not isinstance(self._type, github.Node):
raise AttributeError

return self._type._node_prefix

@property
def _repr_fields(self, /) -> list[str]:
if self._type is MISSING:
raise AttributeError

return self._type._repr_fields

@property
def id(self, /) -> str:
if self._id is MISSING:
raise AttributeError

return self._id


class DummyData(dict):
def __getitem__(self, key: Any, /) -> Any:
return self

def __setitem__(self, key: Any, Value: Any, /) -> None:
return


__all__ = [
"Dummy",
]

0 comments on commit f7babad

Please sign in to comment.