Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[1.16 makes more common] Inference of Any against optional type infers Never #8829

Closed
@rggjan

Description

@rggjan

See the following example:

from typing import Any, Optional, TypeVarT = TypeVar("T")def assert_not_none(value: Optional[T]) -> T:    assert value is not None    return valuedef foo1(a: Optional[Any]) -> int:    return assert_not_none(a)[3]def foo2(a: Optional[Any]) -> int:    assert a is not None    return a[3]

I would expect thatfoo1 andfoo2 are equivalent. However, runningmypy on this file, I get:

test.py:12: error: Value of type <nothing> is not indexable

For some reason,assert_not_none doesn't mapOptional[Any] toAny, as it is supposed to (and which would accept the indexing), but instead maps it to<nothing> which throws an error. The second version with asserting that it is not None seems to work fine, though.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp