Skip to content

Use of resolve generates coroutine never awaited warnings #37

Open
@cbehopkins

Description

@cbehopkins

I have some code that uses resolves, I get the following warning:

831aC:\Python3126\Lib\pathlib.py:1250: RuntimeWarning: coroutine 'AsyncPath.stat' was never awaited
  p.stat()
Object allocated at (most recent call last):
  File "C:\Python3126\Lib\pathlib.py", lineno 1250
    p.stat()

I believe this is caused by, although resolve is awaited, the implementation of resolve uses await to_thread on super().resolve.
The pathlib implementaiton of resolve then does p.stat, which because p (which in the resolve method is generated from self and so) is an AsyncPath. This stat then returns a coroutine, rather than being a simple method as in the default Path implementation.

As a workaround resolve can be passed strict=True which skips the stat check. (This does indeed supress the warning)
A quick fix would probably be to have the AsyncPath resolve method pass a reconstructed Path to the called resolve method, rather than self.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions