Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed support for
transform_descriptor_types
parameter in `datacl…
…ass_transform`, a feature that was determined to be not necessary. Added support on normal dataclass handling for field types that are custom descriptor objects.
- Loading branch information
1 parent
9558239
commit 368dc5e
Showing
6 changed files
with
53 additions
and
98 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
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
44 changes: 44 additions & 0 deletions
44
packages/pyright-internal/src/tests/samples/dataclass19.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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# This sample tests the handling of dataclass fields that use | ||
# descriptor objects. | ||
|
||
from dataclasses import dataclass | ||
from typing import Any, cast, overload | ||
|
||
|
||
class MyDescriptor: | ||
@overload | ||
def __get__(self, __obj: None, __owner: Any) -> "MyDescriptor": | ||
... | ||
|
||
@overload | ||
def __get__(self, __obj: object, __owner: Any) -> int: | ||
... | ||
|
||
def __get__(self, __obj: object | None, __owner: Any) -> "int | MyDescriptor": | ||
if __obj is None: | ||
return self | ||
return cast(Any, __obj)._x | ||
|
||
def __set__(self, __obj: object, __value: int) -> None: | ||
if __obj is not None: | ||
cast(Any, __obj)._x = __value | ||
|
||
|
||
@dataclass | ||
class Foo: | ||
y: MyDescriptor = MyDescriptor() | ||
|
||
|
||
f1 = Foo(3) | ||
|
||
reveal_type(f1.y, expected_text="int") | ||
reveal_type(Foo.y, expected_text="MyDescriptor") | ||
|
||
|
||
# This should generate an error. | ||
f2 = Foo("hi") | ||
|
||
|
||
f3 = Foo() | ||
reveal_type(f3.y, expected_text="int") | ||
|
72 changes: 0 additions & 72 deletions
72
packages/pyright-internal/src/tests/samples/dataclassTransform5.py
This file was deleted.
Oops, something went wrong.
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
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