Add structural Protocol types for TSC item classes#1802
Open
jacalata wants to merge 7 commits into
Open
Conversation
…gs type - Rename DefaultPermissionsEndpoint's local BaseItem alias to DefaultPermissionsTarget to avoid shadowing the new public Protocol - Remove _initial_tags from TaggableItem (internal dirty-tracking detail, not a public contract); update ContentItem docstring to include MetricItem - Narrow WorkbookItem._initial_tags and DatasourceItem._initial_tags annotations from bare set to set[str] for Protocol invariance compliance Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… __all__ Taggable in resource_tagger.py was never used as a type bound -- TaggableItem in base_item.py now covers the public contract. Also remove runtime_checkable import which became unused. Fix pre-existing duplicate SiteOIDCConfiguration entry in models/__init__.__all__. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
ViewItem.owner_id is not independently writable (it tracks the parent workbook's owner), so a plain writable Protocol attribute annotation would mislead mypy. A @Property annotation satisfies both ViewItem's read-only property and the writable instance attributes on other item classes. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add test/test_protocols.py covering isinstance() checks for BaseItem, OwnedItem, TaggableItem, and ContentItem against all representative item classes (WorkbookItem, DatasourceItem, ViewItem, FlowItem, ProjectItem, MetricItem, UserItem) and plain structural objects, including negative cases and protocol-hierarchy checks. - Add _TaggableWithInitial private Protocol in resource_tagger.py to capture the _initial_tags implementation detail alongside the public TaggableItem surface; use it to fully annotate _ResourceTagger._add_tags, _delete_tag, and update_tags. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…test Add section comments to __init__.__all__ to distinguish the new structural protocols from the alphabetical concrete-model list. Move the inline `import datetime` in test_protocols.py to module level, matching the import style used throughout the test suite. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
|
This is great and will make other typing easier. Should they be named differently to clearly differentiate them? Something like |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
base_item.pywith fourruntime_checkableProtocol classes:BaseItem(id, name),OwnedItem(+ owner_id),TaggableItem(+ tags), andContentItem(+ created_at, updated_at), forming a composable hierarchytableauserverclient.modelswith section comments separating them from the concrete model listTaggableprotocol inresource_tagger.pywith a private_TaggableWithInitialand fully annotates all_ResourceTaggermethod signaturesBaseItemtype alias indefault_permissions_endpoint.pytoDefaultPermissionsTargetto avoid shadowing the new public Protocol_initial_tags: settoset[str]inDatasourceItemandWorkbookItemfor Protocol invariance complianceSiteOIDCConfigurationentry frommodels.__all__test/test_protocols.pySchema compliance
All five primary content types in ts-api_3_29.xsd (workbookType, dataSourceType, viewType, flowType, metricType) carry id, name, owner, tags, and createdAt/updatedAt attributes. The Protocol hierarchy matches the schema exactly. MetricItem correctly satisfies ContentItem per schema confirmation.
Test plan
python -m pytest test/test_protocols.py -v-- 41 tests, all passfrom tableauserverclient.models import BaseItem, OwnedItem, TaggableItem, ContentItemworksisinstance(TSC.WorkbookItem(...), ContentItem)returnsTrueat runtime🤖 Generated with Claude Code