Skip to content
Open
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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ classifiers = [
repository = "https://github.com/tableau/server-client-python"

[project.optional-dependencies]
test = ["black==26.3.1", "build", "mypy==1.4", "pytest>=7.0", "pytest-cov", "pytest-subtests",
test = ["black==26.3.1", "build", "mypy==2.3.0", "pytest>=7.0", "pytest-cov", "pytest-subtests",
"pytest-xdist", "requests-mock>=1.0,<2.0", "types-requests>=2.32.4.20250913"]

[tool.setuptools.package-data]
Expand Down
9 changes: 5 additions & 4 deletions tableauserverclient/helpers/strings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from defusedxml.ElementTree import fromstring, tostring
from functools import singledispatch
from typing import TypeVar, overload
from typing import TypeVar, cast, overload

# the redact method can handle either strings or bytes, but it can't mix them.
# Generic type so we can write the actual logic once, then use singledispatch to
Expand All @@ -17,8 +17,9 @@ def _redact_any_type(xml: T, sensitive_word: T, replacement: T, encoding=None) -
matches = root.findall(".//password")
for item in matches:
item.text = "********"
# tostring returns bytes unless an encoding value is passed
return tostring(root, encoding=encoding)
# tostring returns bytes unless an encoding value is passed; cast since
# the callers pass encoding="unicode" for str and None for bytes
return cast(T, tostring(root, encoding=encoding))
except Exception:
# something about the xml handling failed. Just cut off the text at the first occurrence of "password"
location = xml.find(sensitive_word)
Expand All @@ -39,7 +40,7 @@ def _(xml: str) -> str:

@redact_xml.register # type: ignore[no-redef]
def _(xml: bytes) -> bytes:
return _redact_any_type(bytearray(xml), b"password", b"..[redacted]")
return cast(bytes, _redact_any_type(xml, b"password", b"..[redacted]"))


@overload
Expand Down
1 change: 1 addition & 0 deletions test/test_datasource.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pathlib import Path
import tempfile
import unittest
import unittest.mock
from zipfile import ZipFile

from defusedxml.ElementTree import fromstring
Expand Down
Loading