Repository navigation
Action Return TypeDicts #240
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
Open
JVickery-TBS
wants to merge
5
commits into
canada-release
Choose a base branch
from
feature/action-result-typing
base: canada-release
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7bd5651
Merge pull request #239 from open-data/canada-release
JVickery-TBS 03f39a1
feat(dev): typing;
JVickery-TBS fba56da
feat(misc): changelog;
JVickery-TBS 4de8a85
feat(misc): changelog;
JVickery-TBS 025e31b
feat(misc): changelog;
JVickery-TBS File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Added `TypedDict` sub-classes for `package_show`, `resource_show`, and `organization_show` to help improve code type checking. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -26,6 +26,12 @@ | |||||||||||||
| if TYPE_CHECKING: | ||||||||||||||
| from ckanext.activity.model import Activity | ||||||||||||||
|
|
||||||||||||||
| # (canada fork only): TypedDict sub-classes for action results | ||||||||||||||
| # TODO: upstream contrib!!! | ||||||||||||||
| from sqlalchemy.types import DateTime | ||||||||||||||
| from typing_extensions import Required | ||||||||||||||
| from typing import Dict, List | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| __all__ = [ | ||||||||||||||
| "Response", "Request", | ||||||||||||||
|
|
@@ -41,6 +47,11 @@ | |||||||||||||
| "AuthResult", | ||||||||||||||
| "Action", "ChainedAction", "AuthFunction", "ChainedAuthFunction", | ||||||||||||||
| "PFeed", "PFeedFactory", "PResourceUploader", "PUploader", | ||||||||||||||
| # (canada fork only): TypedDict sub-classes for action results | ||||||||||||||
| # TODO: upstream contrib!!! | ||||||||||||||
| 'ExtrasDict', 'TagDict', 'TrackingSummaryDict', | ||||||||||||||
| 'ResourceShowDict', 'PackageShowDict', 'GroupPackageDict', | ||||||||||||||
| 'GroupMemberDict', 'OrganizationShowDict' | ||||||||||||||
| ] | ||||||||||||||
| Config: TypeAlias = Dict[str, Union[str, Mapping[str, str]]] | ||||||||||||||
| CKANApp = Any | ||||||||||||||
|
|
@@ -242,3 +253,155 @@ def get_path(self, id: str) -> str: | |||||||||||||
|
|
||||||||||||||
| def upload(self, id: str, max_size: int = ...) -> None: | ||||||||||||||
| ... | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| # (canada fork only): TypedDict sub-classes for action results | ||||||||||||||
| # TODO: upstream contrib!!! | ||||||||||||||
| class ExtrasDict(TypedDict, total=False): | ||||||||||||||
| ''' | ||||||||||||||
| Dictionary for object extras. | ||||||||||||||
|
|
||||||||||||||
| see: ckan.logic.schema.default_tags_schema | ||||||||||||||
| ''' | ||||||||||||||
| id: str | ||||||||||||||
| key: Required[str] | ||||||||||||||
| value: Required[Any] | ||||||||||||||
| state: str | ||||||||||||||
| deleted: bool | ||||||||||||||
| revision_timestamp: DateTime | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| class TagDict(TypedDict, total=False): | ||||||||||||||
| ''' | ||||||||||||||
| Dictionary for tags. | ||||||||||||||
|
|
||||||||||||||
| see: ckan.logic.schema.default_tags_schema | ||||||||||||||
| ''' | ||||||||||||||
| name: Required[str] | ||||||||||||||
| vocabulary_id: str | ||||||||||||||
| revision_timestamp: DateTime | ||||||||||||||
| state: str | ||||||||||||||
| display_name: str | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| class TrackingSummaryDict(TypedDict): | ||||||||||||||
| ''' | ||||||||||||||
| Dictionary for tracking summaries. | ||||||||||||||
|
|
||||||||||||||
| see: ckan.model.tracking:TrackingSummary | ||||||||||||||
| ''' | ||||||||||||||
| total: int | ||||||||||||||
| recent: int | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| class ResourceShowDict(TypedDict, total=False): | ||||||||||||||
| ''' | ||||||||||||||
| Dictionary returned from the resource_show action. | ||||||||||||||
|
Comment on lines
+297
to
+299
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
|
|
||||||||||||||
| see: ckan.logic.schema.default_show_package_schema | ||||||||||||||
| ''' | ||||||||||||||
| id: Required[str] | ||||||||||||||
| package_id: Required[str] | ||||||||||||||
| url: str | ||||||||||||||
| description: str | ||||||||||||||
| format: str | ||||||||||||||
| hash: str | ||||||||||||||
| state: str | ||||||||||||||
| position: int | ||||||||||||||
| name: str | ||||||||||||||
| resource_type: str | ||||||||||||||
| url_type: str | ||||||||||||||
| mimetype: str | ||||||||||||||
| mimetype_inner: str | ||||||||||||||
| cache_url: str | ||||||||||||||
| size: int | ||||||||||||||
| created: Required[DateTime] | ||||||||||||||
| last_modified: DateTime | ||||||||||||||
| metadata_modified: DateTime | ||||||||||||||
| cache_last_updated: DateTime | ||||||||||||||
| datastore_active: bool | ||||||||||||||
| tracking_summary: TrackingSummaryDict | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| class PackageShowDict(TypedDict, total=False): | ||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
| ''' | ||||||||||||||
| Dictionary returned from the package_show action. | ||||||||||||||
|
|
||||||||||||||
| see: ckan.logic.schema.default_show_package_schema | ||||||||||||||
| ''' | ||||||||||||||
| id: Required[str] | ||||||||||||||
| name: Optional[str] | ||||||||||||||
| title: str | ||||||||||||||
| notes: str | ||||||||||||||
| type: str | ||||||||||||||
| url: str | ||||||||||||||
| version: str | ||||||||||||||
| metadata_created: Required[DateTime] | ||||||||||||||
| metadata_modified: DateTime | ||||||||||||||
| plugin_data: Dict[str, Any] | ||||||||||||||
| private: bool | ||||||||||||||
| state: str | ||||||||||||||
| isopen: bool | ||||||||||||||
| license_url: str | ||||||||||||||
| creator_user_id: str | ||||||||||||||
| author: str | ||||||||||||||
| author_email: str | ||||||||||||||
| maintainer: str | ||||||||||||||
| maintainer_email: str | ||||||||||||||
| license_id: str | ||||||||||||||
| license_title: str | ||||||||||||||
| tracking_summary: TrackingSummaryDict | ||||||||||||||
| owner_org: str | ||||||||||||||
| organization: OrganizationShowDict | ||||||||||||||
| resources: List[ResourceShowDict] | ||||||||||||||
| num_resources: int | ||||||||||||||
| tags: List[TagDict] | ||||||||||||||
| tag_string: str | ||||||||||||||
| num_tags: int | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| class GroupPackageDict(TypedDict, total=False): | ||||||||||||||
| ''' | ||||||||||||||
| Dictionary part of a group's packages. | ||||||||||||||
|
|
||||||||||||||
| see: ckan.logic.schema.default_group_schema | ||||||||||||||
| ''' | ||||||||||||||
| id: Required[str] | ||||||||||||||
| title: str | ||||||||||||||
| name: str | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| class GroupMemberDict(TypedDict, total=False): | ||||||||||||||
| ''' | ||||||||||||||
| Dictionary part of a group's users and groups. | ||||||||||||||
|
|
||||||||||||||
| see: ckan.logic.schema.default_group_schema | ||||||||||||||
| ''' | ||||||||||||||
| name: Required[str] | ||||||||||||||
| capacity: str | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| class OrganizationShowDict(TypedDict, total=False): | ||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
| ''' | ||||||||||||||
| Dictionary returned from the organization_show action. | ||||||||||||||
|
|
||||||||||||||
| see: ckan.logic.schema.default_show_group_schema | ||||||||||||||
| ''' | ||||||||||||||
| id: Required[str] | ||||||||||||||
| name: Required[str] | ||||||||||||||
| title: str | ||||||||||||||
| description: str | ||||||||||||||
| image_url: str | ||||||||||||||
| image_display_url: str | ||||||||||||||
| type: str | ||||||||||||||
| state: str | ||||||||||||||
| created: DateTime | ||||||||||||||
| is_organization: bool | ||||||||||||||
| approval_status: str | ||||||||||||||
| extras: List[ExtrasDict] | ||||||||||||||
| packages: List[GroupPackageDict] | ||||||||||||||
| users: List[GroupMemberDict] | ||||||||||||||
| groups: List[GroupMemberDict] | ||||||||||||||
| num_followers: int | ||||||||||||||
| display_name: str | ||||||||||||||
| package_count: int | ||||||||||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: extras dicts have gone away upstream