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

Fix: literal cannot use unset const #117

Merged
merged 1 commit into from
Jul 19, 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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion codegen/templates/rest/_param.py.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ headers: Optional[Dict[str, str]] = None,
{{ header_params(endpoint) }}
{{ cookie_params(endpoint) }}
*,
data: Literal[UNSET] = UNSET,
data: UnsetType = UNSET,
headers: Optional[Dict[str, str]] = None,
{{ body_params(model, endpoint.param_names) }}
{% endmacro %}
Expand Down
2 changes: 1 addition & 1 deletion codegen/templates/rest/client.py.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ from typing import TYPE_CHECKING, Dict, Literal, Optional, overload

from pydantic import BaseModel, Field

from githubkit.typing import Missing
from githubkit.typing import Missing, UnsetType
from githubkit.utils import exclude_unset, UNSET
from githubkit.compat import model_dump, type_validate_python

Expand Down
30 changes: 15 additions & 15 deletions githubkit/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
Type,
Union,
Generic,
Literal,
TypeVar,
Optional,
Generator,
Expand All @@ -28,23 +27,24 @@
from .compat import to_jsonable_python
from .config import Config, get_config
from .auth import BaseAuthStrategy, TokenAuthStrategy, UnauthAuthStrategy
from .exception import (
RequestError,
RequestFailed,
RequestTimeout,
GitHubException,
PrimaryRateLimitExceeded,
SecondaryRateLimitExceeded,
)
from .typing import (
URLTypes,
UnsetType,
CookieTypes,
HeaderTypes,
ContentTypes,
RequestFiles,
QueryParamTypes,
RetryDecisionFunc,
)
from .exception import (
RequestError,
RequestFailed,
RequestTimeout,
GitHubException,
PrimaryRateLimitExceeded,
SecondaryRateLimitExceeded,
)

T = TypeVar("T")
A = TypeVar("A", bound="BaseAuthStrategy")
Expand Down Expand Up @@ -332,14 +332,14 @@ def _check(
def _check(
self,
response: httpx.Response,
response_model: Literal[UNSET] = UNSET,
response_model: UnsetType = UNSET,
error_models: Optional[Dict[str, type]] = None,
) -> Response[Any]: ...

def _check(
self,
response: httpx.Response,
response_model: Union[Type[T], Literal[UNSET]] = UNSET,
response_model: Union[Type[T], UnsetType] = UNSET,
error_models: Optional[Dict[str, type]] = None,
) -> Union[Response[T], Response[Any]]:
if response.is_error:
Expand Down Expand Up @@ -446,7 +446,7 @@ def request(
json: Optional[Any] = None,
headers: Optional[HeaderTypes] = None,
cookies: Optional[CookieTypes] = None,
response_model: Literal[UNSET] = UNSET,
response_model: UnsetType = UNSET,
error_models: Optional[Dict[str, type]] = None,
) -> Response[Any]: ...

Expand All @@ -462,7 +462,7 @@ def request(
json: Optional[Any] = None,
headers: Optional[HeaderTypes] = None,
cookies: Optional[CookieTypes] = None,
response_model: Union[Type[T], Literal[UNSET]] = UNSET,
response_model: Union[Type[T], UnsetType] = UNSET,
error_models: Optional[Dict[str, type]] = None,
) -> Union[Response[T], Response[Any]]:
retry_count: int = 0
Expand Down Expand Up @@ -523,7 +523,7 @@ async def arequest(
json: Optional[Any] = None,
headers: Optional[HeaderTypes] = None,
cookies: Optional[CookieTypes] = None,
response_model: Literal[UNSET] = UNSET,
response_model: UnsetType = UNSET,
error_models: Optional[Dict[str, type]] = None,
) -> Response[Any]: ...

Expand All @@ -539,7 +539,7 @@ async def arequest(
json: Optional[Any] = None,
headers: Optional[HeaderTypes] = None,
cookies: Optional[CookieTypes] = None,
response_model: Union[Type[T], Literal[UNSET]] = UNSET,
response_model: Union[Type[T], UnsetType] = UNSET,
error_models: Optional[Dict[str, type]] = None,
) -> Union[Response[T], Response[Any]]:
retry_count: int = 0
Expand Down
4 changes: 4 additions & 0 deletions githubkit/rest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4586,6 +4586,9 @@
from githubkit.versions.v2022_11_28.models import (
OrgsOrgActionsRunnersRunnerIdLabelsGetResponse200 as OrgsOrgActionsRunnersRunnerIdLabelsGetResponse200,
)
from githubkit.versions.v2022_11_28.models import (
OrgsOrgCodeSecurityConfigurationsDetachDeleteBody as OrgsOrgCodeSecurityConfigurationsDetachDeleteBody,
)
from githubkit.versions.v2022_11_28.models import (
OrgsOrgCopilotBillingSelectedTeamsPostResponse201 as OrgsOrgCopilotBillingSelectedTeamsPostResponse201,
)
Expand Down Expand Up @@ -12218,6 +12221,7 @@
"OrgsOrgAttestationsSubjectDigestGetResponse200PropAttestationsItemsPropBundlePropVerificationMaterial",
"OrgsOrgAttestationsSubjectDigestGetResponse200PropAttestationsItemsPropBundlePropDsseEnvelope",
"OrgsOrgCodeSecurityConfigurationsPostBody",
"OrgsOrgCodeSecurityConfigurationsDetachDeleteBody",
"OrgsOrgCodeSecurityConfigurationsConfigurationIdPatchBody",
"OrgsOrgCodeSecurityConfigurationsConfigurationIdAttachPostBody",
"OrgsOrgCodeSecurityConfigurationsConfigurationIdDefaultsPutBody",
Expand Down
6 changes: 4 additions & 2 deletions githubkit/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import httpx
from pydantic import Field

from .utils import UNSET
from .utils import Unset
from .compat import PYDANTIC_V2
from .exception import GitHubException

Expand Down Expand Up @@ -76,9 +76,11 @@ def _validate_unique_list(value: List[H]) -> List[H]:
else: # pragma: pydantic-v1
UniqueList: TypeAlias = Annotated[List[H], Field(unique_items=True)] # type: ignore

UnsetType: TypeAlias = Literal[Unset._UNSET]

# if the property is not required, we allow it to have the value null.
# See https://github.com/yanyongyu/githubkit/issues/47
Missing: TypeAlias = Union[Literal[UNSET], T, None]
Missing: TypeAlias = Union[UnsetType, T, None]


class RetryOption(NamedTuple):
Expand Down
Loading
Loading