Skip to content

Feature: use arbitrary dict type for object with extra properties #183

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

Merged
merged 1 commit into from
Jan 15, 2025
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
3 changes: 3 additions & 0 deletions codegen/parser/schemas/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,9 @@ def get_type_imports(self) -> set[str]:
imports = {"from typing_extensions import TypedDict"}
for prop in self.properties:
imports.update(prop.get_type_imports())
if self.allow_extra:
imports.add("from typing import Any")
imports.add("from typing_extensions import TypeAlias")
return imports

@override
Expand Down
8 changes: 8 additions & 0 deletions codegen/templates/models/type_group.py.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,20 @@ from .{{ group_name(group.get_dependency_by_model(model), groups) }} import {{ m
{# model #}
{% for model in group.models %}

{# if model has no property and allows extra properties #}
{# we treat it as arbitrary dict #}
{# TODO: PEP728 TypedDict with extra items #}
{% if not model.properties and model.allow_extra %}
{{ model.class_name }}Type: TypeAlias = dict[str, Any]
{{ build_model_docstring(model) }}
{% else %}
class {{ model.class_name }}Type(TypedDict):
{{ build_model_docstring(model) | indent(4) }}

{% for prop in model.properties %}
{{ prop.get_type_defination() }}
{% endfor %}
{% endif %}

{% endfor %}

Expand Down
1 change: 1 addition & 0 deletions githubkit/versions/ghec_v2022_11_28/models/group_0061.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class EnterpriseTeam(GitHubModel):
url: str = Field()
sync_to_organizations: str = Field()
group_id: Missing[Union[str, None]] = Field(default=UNSET)
group_name: Missing[Union[str, None]] = Field(default=UNSET)
html_url: str = Field()
members_url: str = Field()
created_at: datetime = Field()
Expand Down
8 changes: 4 additions & 4 deletions githubkit/versions/ghec_v2022_11_28/models/group_0232.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@


class CheckAutomatedSecurityFixes(GitHubModel):
"""Check Automated Security Fixes
"""Check Dependabot security updates

Check Automated Security Fixes
Check Dependabot security updates
"""

enabled: bool = Field(
description="Whether automated security fixes are enabled for the repository."
description="Whether Dependabot security updates are enabled for the repository."
)
paused: bool = Field(
description="Whether automated security fixes are paused for the repository."
description="Whether Dependabot security updates are paused for the repository."
)


Expand Down
12 changes: 6 additions & 6 deletions githubkit/versions/ghec_v2022_11_28/rest/repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -2707,7 +2707,7 @@ def check_automated_security_fixes(
*,
headers: Optional[Mapping[str, str]] = None,
) -> Response[CheckAutomatedSecurityFixes, CheckAutomatedSecurityFixesType]:
"""See also: https://docs.github.com/enterprise-cloud@latest//rest/repos/repos#check-if-automated-security-fixes-are-enabled-for-a-repository"""
"""See also: https://docs.github.com/enterprise-cloud@latest//rest/repos/repos#check-if-dependabot-security-updates-are-enabled-for-a-repository"""

from ..models import CheckAutomatedSecurityFixes

Expand All @@ -2730,7 +2730,7 @@ async def async_check_automated_security_fixes(
*,
headers: Optional[Mapping[str, str]] = None,
) -> Response[CheckAutomatedSecurityFixes, CheckAutomatedSecurityFixesType]:
"""See also: https://docs.github.com/enterprise-cloud@latest//rest/repos/repos#check-if-automated-security-fixes-are-enabled-for-a-repository"""
"""See also: https://docs.github.com/enterprise-cloud@latest//rest/repos/repos#check-if-dependabot-security-updates-are-enabled-for-a-repository"""

from ..models import CheckAutomatedSecurityFixes

Expand All @@ -2753,7 +2753,7 @@ def enable_automated_security_fixes(
*,
headers: Optional[Mapping[str, str]] = None,
) -> Response:
"""See also: https://docs.github.com/enterprise-cloud@latest//rest/repos/repos#enable-automated-security-fixes"""
"""See also: https://docs.github.com/enterprise-cloud@latest//rest/repos/repos#enable-dependabot-security-updates"""

url = f"/repos/{owner}/{repo}/automated-security-fixes"

Expand All @@ -2772,7 +2772,7 @@ async def async_enable_automated_security_fixes(
*,
headers: Optional[Mapping[str, str]] = None,
) -> Response:
"""See also: https://docs.github.com/enterprise-cloud@latest//rest/repos/repos#enable-automated-security-fixes"""
"""See also: https://docs.github.com/enterprise-cloud@latest//rest/repos/repos#enable-dependabot-security-updates"""

url = f"/repos/{owner}/{repo}/automated-security-fixes"

Expand All @@ -2791,7 +2791,7 @@ def disable_automated_security_fixes(
*,
headers: Optional[Mapping[str, str]] = None,
) -> Response:
"""See also: https://docs.github.com/enterprise-cloud@latest//rest/repos/repos#disable-automated-security-fixes"""
"""See also: https://docs.github.com/enterprise-cloud@latest//rest/repos/repos#disable-dependabot-security-updates"""

url = f"/repos/{owner}/{repo}/automated-security-fixes"

Expand All @@ -2810,7 +2810,7 @@ async def async_disable_automated_security_fixes(
*,
headers: Optional[Mapping[str, str]] = None,
) -> Response:
"""See also: https://docs.github.com/enterprise-cloud@latest//rest/repos/repos#disable-automated-security-fixes"""
"""See also: https://docs.github.com/enterprise-cloud@latest//rest/repos/repos#disable-dependabot-security-updates"""

url = f"/repos/{owner}/{repo}/automated-security-fixes"

Expand Down
28 changes: 14 additions & 14 deletions githubkit/versions/ghec_v2022_11_28/types/group_0013.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from __future__ import annotations

from datetime import datetime
from typing import Union
from typing_extensions import NotRequired, TypedDict
from typing import Any, Union
from typing_extensions import NotRequired, TypeAlias, TypedDict


class HookDeliveryType(TypedDict):
Expand Down Expand Up @@ -44,18 +44,18 @@ class HookDeliveryPropRequestType(TypedDict):
payload: Union[HookDeliveryPropRequestPropPayloadType, None]


class HookDeliveryPropRequestPropHeadersType(TypedDict):
"""HookDeliveryPropRequestPropHeaders
HookDeliveryPropRequestPropHeadersType: TypeAlias = dict[str, Any]
"""HookDeliveryPropRequestPropHeaders

The request headers sent with the webhook delivery.
"""
The request headers sent with the webhook delivery.
"""


class HookDeliveryPropRequestPropPayloadType(TypedDict):
"""HookDeliveryPropRequestPropPayload
HookDeliveryPropRequestPropPayloadType: TypeAlias = dict[str, Any]
"""HookDeliveryPropRequestPropPayload

The webhook payload.
"""
The webhook payload.
"""


class HookDeliveryPropResponseType(TypedDict):
Expand All @@ -65,11 +65,11 @@ class HookDeliveryPropResponseType(TypedDict):
payload: Union[str, None]


class HookDeliveryPropResponsePropHeadersType(TypedDict):
"""HookDeliveryPropResponsePropHeaders
HookDeliveryPropResponsePropHeadersType: TypeAlias = dict[str, Any]
"""HookDeliveryPropResponsePropHeaders

The response headers received when the delivery was made.
"""
The response headers received when the delivery was made.
"""


__all__ = (
Expand Down
8 changes: 5 additions & 3 deletions githubkit/versions/ghec_v2022_11_28/types/group_0041.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

from __future__ import annotations

from typing_extensions import NotRequired, TypedDict
from typing import Any
from typing_extensions import NotRequired, TypeAlias, TypedDict


class AuditLogEventType(TypedDict):
Expand Down Expand Up @@ -66,8 +67,9 @@ class AuditLogEventPropActorLocationType(TypedDict):
country_name: NotRequired[str]


class AuditLogEventPropDataType(TypedDict):
"""AuditLogEventPropData"""
AuditLogEventPropDataType: TypeAlias = dict[str, Any]
"""AuditLogEventPropData
"""


class AuditLogEventPropConfigItemsType(TypedDict):
Expand Down
1 change: 1 addition & 0 deletions githubkit/versions/ghec_v2022_11_28/types/group_0061.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class EnterpriseTeamType(TypedDict):
url: str
sync_to_organizations: str
group_id: NotRequired[Union[str, None]]
group_name: NotRequired[Union[str, None]]
html_url: str
members_url: str
created_at: datetime
Expand Down
7 changes: 4 additions & 3 deletions githubkit/versions/ghec_v2022_11_28/types/group_0135.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from datetime import datetime
from typing import Any, Union
from typing_extensions import NotRequired, TypedDict
from typing_extensions import NotRequired, TypeAlias, TypedDict

from .group_0002 import SimpleUserType

Expand Down Expand Up @@ -45,8 +45,9 @@ class BaseGistType(TypedDict):
history: NotRequired[list[Any]]


class BaseGistPropFilesType(TypedDict):
"""BaseGistPropFiles"""
BaseGistPropFilesType: TypeAlias = dict[str, Any]
"""BaseGistPropFiles
"""


__all__ = (
Expand Down
7 changes: 4 additions & 3 deletions githubkit/versions/ghec_v2022_11_28/types/group_0136.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from datetime import datetime
from typing import Any, Union
from typing_extensions import NotRequired, TypedDict
from typing_extensions import NotRequired, TypeAlias, TypedDict

from .group_0002 import SimpleUserType

Expand Down Expand Up @@ -66,8 +66,9 @@ class GistSimplePropForkOfType(TypedDict):
history: NotRequired[list[Any]]


class GistSimplePropForkOfPropFilesType(TypedDict):
"""GistSimplePropForkOfPropFiles"""
GistSimplePropForkOfPropFilesType: TypeAlias = dict[str, Any]
"""GistSimplePropForkOfPropFiles
"""


__all__ = (
Expand Down
9 changes: 5 additions & 4 deletions githubkit/versions/ghec_v2022_11_28/types/group_0137.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from __future__ import annotations

from datetime import datetime
from typing import Union
from typing_extensions import NotRequired, TypedDict
from typing import Any, Union
from typing_extensions import NotRequired, TypeAlias, TypedDict

from .group_0002 import SimpleUserType
from .group_0136 import GistHistoryType, GistSimplePropForkOfType
Expand Down Expand Up @@ -47,8 +47,9 @@ class GistSimpleType(TypedDict):
truncated: NotRequired[bool]


class GistSimplePropFilesType(TypedDict):
"""GistSimplePropFiles"""
GistSimplePropFilesType: TypeAlias = dict[str, Any]
"""GistSimplePropFiles
"""


class GistSimplePropForksItemsType(TypedDict):
Expand Down
29 changes: 17 additions & 12 deletions githubkit/versions/ghec_v2022_11_28/types/group_0186.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

from __future__ import annotations

from typing import Literal, Union
from typing_extensions import NotRequired, TypedDict
from typing import Any, Literal, Union
from typing_extensions import NotRequired, TypeAlias, TypedDict

from .group_0002 import SimpleUserType

Expand Down Expand Up @@ -53,20 +53,25 @@ class OrganizationProgrammaticAccessGrantRequestPropPermissionsType(TypedDict):
]


class OrganizationProgrammaticAccessGrantRequestPropPermissionsPropOrganizationType(
TypedDict
):
"""OrganizationProgrammaticAccessGrantRequestPropPermissionsPropOrganization"""
OrganizationProgrammaticAccessGrantRequestPropPermissionsPropOrganizationType: TypeAlias = dict[
str, Any
]
"""OrganizationProgrammaticAccessGrantRequestPropPermissionsPropOrganization
"""


class OrganizationProgrammaticAccessGrantRequestPropPermissionsPropRepositoryType(
TypedDict
):
"""OrganizationProgrammaticAccessGrantRequestPropPermissionsPropRepository"""
OrganizationProgrammaticAccessGrantRequestPropPermissionsPropRepositoryType: TypeAlias = dict[
str, Any
]
"""OrganizationProgrammaticAccessGrantRequestPropPermissionsPropRepository
"""


class OrganizationProgrammaticAccessGrantRequestPropPermissionsPropOtherType(TypedDict):
"""OrganizationProgrammaticAccessGrantRequestPropPermissionsPropOther"""
OrganizationProgrammaticAccessGrantRequestPropPermissionsPropOtherType: TypeAlias = (
dict[str, Any]
)
"""OrganizationProgrammaticAccessGrantRequestPropPermissionsPropOther
"""


__all__ = (
Expand Down
25 changes: 17 additions & 8 deletions githubkit/versions/ghec_v2022_11_28/types/group_0187.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

from __future__ import annotations

from typing import Literal, Union
from typing_extensions import NotRequired, TypedDict
from typing import Any, Literal, Union
from typing_extensions import NotRequired, TypeAlias, TypedDict

from .group_0002 import SimpleUserType

Expand Down Expand Up @@ -50,16 +50,25 @@ class OrganizationProgrammaticAccessGrantPropPermissionsType(TypedDict):
other: NotRequired[OrganizationProgrammaticAccessGrantPropPermissionsPropOtherType]


class OrganizationProgrammaticAccessGrantPropPermissionsPropOrganizationType(TypedDict):
"""OrganizationProgrammaticAccessGrantPropPermissionsPropOrganization"""
OrganizationProgrammaticAccessGrantPropPermissionsPropOrganizationType: TypeAlias = (
dict[str, Any]
)
"""OrganizationProgrammaticAccessGrantPropPermissionsPropOrganization
"""


class OrganizationProgrammaticAccessGrantPropPermissionsPropRepositoryType(TypedDict):
"""OrganizationProgrammaticAccessGrantPropPermissionsPropRepository"""
OrganizationProgrammaticAccessGrantPropPermissionsPropRepositoryType: TypeAlias = dict[
str, Any
]
"""OrganizationProgrammaticAccessGrantPropPermissionsPropRepository
"""


class OrganizationProgrammaticAccessGrantPropPermissionsPropOtherType(TypedDict):
"""OrganizationProgrammaticAccessGrantPropPermissionsPropOther"""
OrganizationProgrammaticAccessGrantPropPermissionsPropOtherType: TypeAlias = dict[
str, Any
]
"""OrganizationProgrammaticAccessGrantPropPermissionsPropOther
"""


__all__ = (
Expand Down
16 changes: 8 additions & 8 deletions githubkit/versions/ghec_v2022_11_28/types/group_0193.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from __future__ import annotations

from datetime import datetime
from typing import Literal, Union
from typing_extensions import NotRequired, TypedDict
from typing import Any, Literal, Union
from typing_extensions import NotRequired, TypeAlias, TypedDict

from .group_0002 import SimpleUserType
from .group_0018 import LicenseSimpleType
Expand Down Expand Up @@ -143,13 +143,13 @@ class FullRepositoryPropPermissionsType(TypedDict):
pull: bool


class FullRepositoryPropCustomPropertiesType(TypedDict):
"""FullRepositoryPropCustomProperties
FullRepositoryPropCustomPropertiesType: TypeAlias = dict[str, Any]
"""FullRepositoryPropCustomProperties

The custom properties that were defined for the repository. The keys are the
custom property names, and the values are the corresponding custom property
values.
"""
The custom properties that were defined for the repository. The keys are the
custom property names, and the values are the corresponding custom property
values.
"""


__all__ = (
Expand Down
Loading
Loading