There is a consistency discrepancy in asyncssh.SFTPClient.realpath when it returns an SFTPName object.
In most asyncssh SFTP APIs, the return type matches the input type: if a str or PurePath is provided, a str is returned; if bytes are provided, bytes are returned. However, when realpath() is called with check=FXRP_STAT_IF_EXISTS (or other flags that trigger an SFTPName return), the filename attribute of the resulting object is always bytes, regardless of the input type.
Reproduction Code
import asyncio
import asyncssh
from asyncssh import FXRP_STAT_IF_EXISTS
async def main():
async with (
asyncssh.connect('host', username='user', password='pw', known_hosts=None) as conn,
conn.start_sftp_client() as sftp,
):
path = await sftp.realpath('a')
print(type(path)) # <class 'str'>
sftp_name = await sftp.realpath('a', check=FXRP_STAT_IF_EXISTS)
print(type(sftp_name.filename)) # <class 'bytes'>
asyncio.run(main())
Expected Behavior
If the input to realpath is a str, sftp_name.filename should be a str to maintain consistency with the rest of the library's SFTP file-handling logic.
Actual Behavior
sftp_name.filename is returned as bytes, requiring manual decoding even when the rest of the session uses string paths.
There is a consistency discrepancy in
asyncssh.SFTPClient.realpathwhen it returns anSFTPNameobject.In most
asyncsshSFTP APIs, the return type matches the input type: if astrorPurePathis provided, astris returned; ifbytesare provided,bytesare returned. However, whenrealpath()is called withcheck=FXRP_STAT_IF_EXISTS(or other flags that trigger anSFTPNamereturn), thefilenameattribute of the resulting object is alwaysbytes, regardless of the input type.Reproduction Code
Expected Behavior
If the input to
realpathis astr,sftp_name.filenameshould be astrto maintain consistency with the rest of the library's SFTP file-handling logic.Actual Behavior
sftp_name.filenameis returned asbytes, requiring manual decoding even when the rest of the session uses string paths.