Skip to content

Commit 1b8eae4

Browse files
jacalataclaude
andcommitted
fix: resolve mypy 2.3 errors in strings.py and test_datasource.py
- strings.py: cast tostring() return value to T since mypy 2.3 no longer accepts bytes as compatible with TypeVar T constrained to str|bytes - test_datasource.py: add explicit `import unittest.mock` since mypy 2.3 no longer resolves submodule attributes through the parent import Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 56b0ba4 commit 1b8eae4

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

tableauserverclient/helpers/strings.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from defusedxml.ElementTree import fromstring, tostring
22
from functools import singledispatch
3-
from typing import TypeVar, overload
3+
from typing import TypeVar, cast, overload
44

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

test/test_datasource.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from pathlib import Path
44
import tempfile
55
import unittest
6+
import unittest.mock
67
from zipfile import ZipFile
78

89
from defusedxml.ElementTree import fromstring

0 commit comments

Comments
 (0)