@@ -231,7 +231,7 @@ def download_file(
231231
232232 def upload_file (
233233 self ,
234- source : Union ["LocalFileController" , "WikiFileController" , str , Path ],
234+ source : Union ["LocalFileController" , "WikiFileController" , str , Path , IO ],
235235 url_or_title : Optional [str ] = None ,
236236 overwrite : OVERWRITE_CLASS_OPTIONS = OverwriteOptions .true ,
237237 delete_after_use : bool = False ,
@@ -247,7 +247,7 @@ def upload_file(
247247 ----------
248248 source
249249 The source file to upload. Can be a LocalFileController, WikiFileController,
250- str or Path .
250+ str, Path or an open file-like object .
251251 url_or_title
252252 The URL or full page title of the WikiFile page to upload the file to. Used to
253253 overwrite autogenerated full page title on the target domain. If it is
@@ -635,7 +635,9 @@ def __init__(
635635 data ["path" ] = Path (source )
636636 data ["source" ] = Path (source )
637637 data ["source_file_controller" ] = LocalFileController (path = data .get ("path" ))
638- elif isinstance (source , IO ):
638+ # duck-typed: typing.IO is not runtime-checkable, isinstance(BytesIO(), IO)
639+ # is False, so an explicit isinstance check would never match a stream
640+ elif hasattr (source , "read" ):
639641 data ["source_file_controller" ] = InMemoryController (stream = source )
640642 else :
641643 raise ValueError (
@@ -736,7 +738,7 @@ def __init__(
736738
737739
738740def osw_upload_file (
739- source : Union [LocalFileController , WikiFileController , str , Path ],
741+ source : Union [LocalFileController , WikiFileController , str , Path , IO ],
740742 url_or_title : Optional [str ] = None ,
741743 overwrite : OVERWRITE_CLASS_OPTIONS = OverwriteOptions .true ,
742744 delete_after_use : bool = False ,
@@ -756,7 +758,7 @@ def osw_upload_file(
756758 ----------
757759 source
758760 The source file to upload. Can be a LocalFileController, WikiFileController,
759- str or Path .
761+ str, Path or an open file-like object .
760762 url_or_title
761763 The URL or full page title of the WikiFile page to upload the file to. Used to
762764 overwrite autogenerated full page title on the target domain. If it is
0 commit comments