Skip to content

assertion/util: improve typing#14383

Open
bluetech wants to merge 3 commits intopytest-dev:mainfrom
bluetech:assertion-util-typing
Open

assertion/util: improve typing#14383
bluetech wants to merge 3 commits intopytest-dev:mainfrom
bluetech:assertion-util-typing

Conversation

@bluetech
Copy link
Copy Markdown
Member

Change Anys to object. It's better to use object for "unknown" -- object is type safe, Any is not.

To aid in this, change the is* functions to TypeGuards, so their check is carried over to the typing.

Since pytest already uses dataclasses extensively internally, I removed the lazy import of it, this way can more easily utilize the existing type guard from typeshed.

Change `Any`s to `object`. It's better to use `object` for "unknown" --
`object` is type safe, `Any` is not.

To aid in this, change the `is*` functions to TypeGuards, so their check
is carried over to the typing.

Since pytest already uses dataclasses extensively internally, I removed
the lazy import of it, this way can more easily utilize the existing
type guard from typeshed.
@bluetech bluetech added the skip news used on prs to opt out of the changelog requirement label Apr 11, 2026


def isiterable(obj: Any) -> bool:
def isiterable(obj: object) -> TypeGuard[collections.abc.Iterable[object]]:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one should take object|Iterable[object]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Iterable[object] is a subtype of object, so isn't this equivalent to object?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip news used on prs to opt out of the changelog requirement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants