Skip to content

Commit e84865b

Browse files
authored
Merge pull request #4527 from hssyoo/download-fileobj-append
Ensure fileobj mode is str when checking for append mode
2 parents eebdb47 + 9b51374 commit e84865b

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

boto3/compat.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,8 @@ def _warn_deprecated_python():
8585

8686

8787
def is_append_mode(fileobj):
88-
return hasattr(fileobj, 'mode') and _APPEND_MODE_CHAR in fileobj.mode
88+
return (
89+
hasattr(fileobj, 'mode') and
90+
isinstance(fileobj.mode, str) and
91+
_APPEND_MODE_CHAR in fileobj.mode
92+
)

tests/unit/s3/test_inject.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
13+
import gzip
1314
import io
1415

1516
import pytest
@@ -280,3 +281,15 @@ def test_threading_not_disabled_if_not_append_mode(caplog, tmp_path):
280281
inject.disable_threading_if_append_mode(config, f)
281282
assert config.use_threads is True
282283
assert 'A single thread will be used' not in caplog.text
284+
285+
286+
def test_threading_not_disabled_if_mode_non_string(caplog, tmp_path):
287+
config = TransferConfig(use_threads=True)
288+
with gzip.open(tmp_path / 'myfile', 'wb') as f:
289+
# In Python 3.13, gzip started assigning strings
290+
# instead of integers for mode. Explicitly set
291+
# mode to an integer to ensure we test the right behavior.
292+
f.mode = 2
293+
inject.disable_threading_if_append_mode(config, f)
294+
assert config.use_threads is True
295+
assert 'A single thread will be used' not in caplog.text

0 commit comments

Comments
 (0)