-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
I'd argue the following code is ok, as all default parameters are immutable.
import datetime as dt
from dataclasses import dataclass
from pathlib import Path
MyId = int
@dataclass
class Example:
timedelta: dt.datetime = dt.timedelta(hours=1)
date: dt.date = dt.date(2042, 1, 1)
id: MyId = MyId(5)
path: Path = Path()
e = Example()ruff is not happy though:
ruff009.py:9:30: RUF009 Do not perform function call `dt.timedelta` in dataclass defaults
ruff009.py:11:21: RUF009 Do not perform function call `dt.date` in dataclass defaults
ruff009.py:13:16: RUF009 Do not perform function call `MyId` in dataclass defaults
ruff009.py:15:18: RUF009 Do not perform function call `Path` in dataclass defaults
Isn't there a similar case for default values of method parameters? I think this rule had a list of (at least some) allowed calls.
EDIT: Here is the list: https://github.com/charliermarsh/ruff/blob/main/crates/ruff/src/rules/flake8_bugbear/rules/function_call_argument_default.rs
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working