no-bare-object-annotations

Require annotations to use a more precise boundary type than bare object.

Message

Use a narrower type than bare object in annotations.

Settings

SettingDescriptionTypeDefault
excluded_path_parts Path parts that should be excluded in addition to test_*.py files. list ['tests']

Valid examples

def fn(payload: dict[str, object]) -> None:
    return None
def fn(settings_type: type[object]) -> None:
    return None
sentinel = object()
Show more
from typing import Protocol

class SettingsProvider(Protocol):
    pass

def fn(value: object | SettingsProvider | None) -> None:
    return None
class object:
    pass

def fn(value: object) -> None:
    return None

Invalid examples

def fn(value: object) -> None:
    return None
def fn() -> object:
    return None
value: object = payload
value: object | None = None
Show more
value: None | object = None
from typing import Optional

value: Optional[object] = None
from typing import Union

value: Union[object, None] = None
value: "object" = payload
value: "object" "" = payload
import builtins

value: builtins.object = payload
import builtins as builtin_types

value: builtin_types.object = payload
import builtins
from typing import Optional

value: Optional[builtins.object] = None