forked from microsoft/pyright
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restored previous behavior (prior to 1.1.334) where an instance of a …
…class that derives from `Any` will not be considered type compatible with `None`. This addresses microsoft#6325. (microsoft#6348)
- Loading branch information
Showing
2 changed files
with
25 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 19 additions & 3 deletions
22
packages/pyright-internal/src/tests/samples/memberAccess24.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,36 @@ | ||
# This sample tests the case where an attribute is accessed from a | ||
# class that derives from an unknown type or Any. | ||
|
||
from typing import Any | ||
from typing import Any, overload | ||
from dummy import UnknownX # type: ignore | ||
|
||
|
||
class Desc: | ||
@overload | ||
def __get__(self, instance: None, owner: Any) -> "Desc": | ||
... | ||
|
||
@overload | ||
def __get__(self, instance: object, owner: Any) -> int: | ||
... | ||
|
||
def __get__(self, instance: object | None, owner: Any) -> "Desc | int": | ||
... | ||
|
||
|
||
class DerivesFromUnknown(UnknownX): | ||
pass | ||
y: Desc | ||
|
||
|
||
class DerivesFromAny(Any): | ||
pass | ||
y: Desc | ||
|
||
|
||
v1 = DerivesFromUnknown().x | ||
reveal_type(v1, expected_text="Unknown") | ||
|
||
v2 = DerivesFromAny().x | ||
reveal_type(v2, expected_text="Any") | ||
|
||
reveal_type(DerivesFromUnknown().y, expected_text="int") | ||
reveal_type(DerivesFromAny().y, expected_text="int") |