Skip to content

Uninhabited should have all attributes #19300

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1671,6 +1671,10 @@ def check_call(
object_type,
original_type=callee,
)
elif isinstance(callee, UninhabitedType):
ret = UninhabitedType()
ret.ambiguous = callee.ambiguous
return callee, ret
else:
return self.msg.not_callable(callee, context), AnyType(TypeOfAny.from_error)

Expand Down
5 changes: 5 additions & 0 deletions mypy/checkmember.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
TypeVarLikeType,
TypeVarTupleType,
TypeVarType,
UninhabitedType,
UnionType,
get_proper_type,
)
Expand Down Expand Up @@ -268,6 +269,10 @@ def _analyze_member_access(
if not mx.suppress_errors:
mx.msg.deleted_as_rvalue(typ, mx.context)
return AnyType(TypeOfAny.from_error)
elif isinstance(typ, UninhabitedType):
attr_type = UninhabitedType()
attr_type.ambiguous = typ.ambiguous
return attr_type
return report_missing_attribute(mx.original_type, typ, name, mx)


Expand Down
16 changes: 16 additions & 0 deletions test-data/unit/check-unreachable-code.test
Original file line number Diff line number Diff line change
Expand Up @@ -1587,3 +1587,19 @@ x = 0 # not unreachable

f2: Callable[[], NoReturn] = lambda: foo()
x = 0 # not unreachable

[case testAttributeNoReturn]
# flags: --warn-unreachable
from typing import Optional, NoReturn, TypeVar

def foo() -> NoReturn:
raise

T = TypeVar("T")
def bar(x: Optional[list[T]] = None) -> T:
...

reveal_type(bar().attr) # N: Revealed type is "Never"
1 # not unreachable
reveal_type(foo().attr) # N: Revealed type is "Never"
1 # E: Statement is unreachable
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy