Skip to content

Commit 0881adb

Browse files
committed
fix: address Copilot review feedback on public type aliases
- Parameterize os.PathLike as os.PathLike[str] in FilePath so type checkers get precise element-type info instead of the bare generic form (Copilot review, types.py:7). - Add @runtime_checkable to IDPAttributes and IDPProperty so that isinstance() checks against the re-exported public Protocol types do not raise TypeError. These Protocols are exported from the package root; making them runtime-checkable is required for them to be safe to use as documented public types. - Widen FileObject from `io.BufferedReader | io.BytesIO` to the more idiomatic `typing.BinaryIO`. FileObject is not used as a parameter or return annotation anywhere in the codebase (only re-exported via __init__ / PathOrFile), so the widening is source-compatible for in-repo callers. Public consumers passing a wider binary-file-like object now type-check cleanly. Skipped items: none.
1 parent 8e882a5 commit 0881adb

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

tableauserverclient/types.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import io
22
import os
33
from collections import namedtuple
4-
from typing import Literal, Protocol, TypedDict
4+
from typing import BinaryIO, Literal, Protocol, TypedDict, runtime_checkable
55

66
# File path and object type aliases used across publish/download methods
7-
FilePath = str | os.PathLike
8-
FileObject = io.BufferedReader | io.BytesIO
7+
FilePath = str | os.PathLike[str]
8+
FileObject = BinaryIO
99
FileObjectR = io.BufferedReader | io.BytesIO
1010
FileObjectW = io.BufferedWriter | io.BytesIO
1111
PathOrFile = FilePath | FileObject
@@ -59,10 +59,12 @@
5959
# HasIdpConfigurationID unions both so downstream callers can implement either
6060
# style without hitting mypy invariance errors. Callers accept
6161
# `str | HasIdpConfigurationID` -- passing a raw id string or an object.
62+
@runtime_checkable
6263
class IDPAttributes(Protocol):
6364
idp_configuration_id: str
6465

6566

67+
@runtime_checkable
6668
class IDPProperty(Protocol):
6769
@property
6870
def idp_configuration_id(self) -> str: ...

0 commit comments

Comments
 (0)