Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: false positive FURB111 when asyncio.get_running_loop() #343

Open
3 tasks done
jamesbraza opened this issue Jun 22, 2024 · 0 comments
Open
3 tasks done

[Bug]: false positive FURB111 when asyncio.get_running_loop() #343

jamesbraza opened this issue Jun 22, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@jamesbraza
Copy link

Has your issue already been fixed?

  • Have you checked to see if your issue still exists on the master branch? See the docs for instructions on how to setup a local build of Refurb.
  • Have you looked at the open/closed issues to see if anyone has already reported your issue?
  • If reporting a false positive/incorrect suggestion, have you double checked that the suggested fix changes the code semantics?

The Bug

import asyncio

from pydantic import BaseModel, Field


class Foo(BaseModel):
    start_time: float = Field(
        default_factory=lambda: asyncio.get_running_loop().time()
    )

This code with refurb will want to be Field(default_factory=asyncio.get_running_loop().time) per FURB111.

The issue is that asyncio.get_running_loop can throw RuntimeError: no running event loop depending on when it's invoked.

So the bug report is that if asyncio.get_running_loop is part of a factory, perhaps FURB111 should not be raised.

Version Info

Refurb: v2.0.0
Mypy: v1.10.0

Python Version

Python 3.12.3

Config File

# N/A

Extra Info

None

@jamesbraza jamesbraza added the bug Something isn't working label Jun 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants