no-bare-object-annotations

Disallow object as an entire annotation when a narrower type can be used.

Message

Replace this bare object annotation with a type that describes the value.

Settings

SettingDescriptionTypeDefault
excluded_path_parts Skip files whose path contains any of these components, in addition to files named test_*.py. 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
from typing import Annotated

value: Annotated[object, "metadata"] = payload
from typing import TypeAlias

Object: TypeAlias = object
value: Object = payload