Tinche / aiofiles

File support for asyncio
Apache License 2.0
2.66k stars 150 forks source link

AsyncSpooledTemporaryFile.newlines should be property not method #118

Closed cake-monotone closed 2 years ago

cake-monotone commented 2 years ago
import asyncio
from aiofiles.tempfile import SpooledTemporaryFile

async def main():
    async with SpooledTemporaryFile(mode='r') as f:
        print(await f.newlines())

asyncio.run(main())

this code failed with

Traceback (most recent call last):
  File "temp.py", line 8, in <module>
    asyncio.run(main())
  File "/usr/lib/python3.8/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "temp.py", line 6, in main
    print(await f.newlines())
  File "/home/cake/project/typing-test/.venv/lib/python3.8/site-packages/aiofiles/threadpool/utils.py", line 72, in method
    return getattr(self._file, attr_name)(*args, **kwargs)
TypeError: 'NoneType' object is not callable

newlines of _io.TextIOWrapper is property, not method

https://github.com/Tinche/aiofiles/blob/d010ff4d789598213334a32ec3d3f55caaab766c/src/aiofiles/tempfile/temptypes.py#L21

I think we should move newlines to proxy_property_directly.