dosisod / refurb

A tool for refurbishing and modernizing Python codebases
GNU General Public License v3.0
2.48k stars 54 forks source link

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

Open jamesbraza opened 2 months ago

jamesbraza commented 2 months ago

Has your issue already been fixed?

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