-
-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…H-6812) (cherry picked from commit 3059042) Co-authored-by: Eric V. Smith <ericvsmith@users.noreply.github.com>
- Loading branch information
1 parent
3b26e8c
commit b57aeac
Showing
5 changed files
with
84 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from __future__ import annotations | ||
from dataclasses import dataclass | ||
from typing import List | ||
from typing import ClassVar as CV | ||
|
||
@dataclass | ||
class A: | ||
a: List[str] | ||
|
||
@dataclass | ||
class B(A): | ||
b: CV[int] |
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,15 @@ | ||
|
||
class X: | ||
def __init__(self, value): | ||
self.value = value | ||
def __str__(self): | ||
return str(self.value) | ||
def __format__(self, fmt): | ||
assert fmt[0] == '=' | ||
self.value = eval(fmt[1:]) | ||
return '' | ||
|
||
x = X(3) | ||
print(x) | ||
f'{x:=4}' # Behold! | ||
print(x) |
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,20 @@ | ||
from dataclasses import * | ||
|
||
class D: | ||
"""A descriptor class that knows its name.""" | ||
def __set_name__(self, owner, name): | ||
self.name = name | ||
def __get__(self, instance, owner): | ||
if instance is not None: | ||
return 1 | ||
return self | ||
|
||
from dataclasses import * | ||
|
||
@dataclass | ||
class C: | ||
d: int = field(default=D(), init=False) | ||
|
||
@dataclass | ||
class E(C): | ||
e: int = field(default=D(), init=False) |
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,31 @@ | ||
#from __future__ import annotations | ||
from typing import ClassVar, Dict, get_type_hints | ||
from dataclasses import * | ||
|
||
class Starship: | ||
stats: ClassVar[Dict[str, int]] = {} | ||
|
||
#print(get_type_hints(Starship)) | ||
|
||
#class A: | ||
# a: Dict[int, C] | ||
|
||
#print(get_type_hints(A)) | ||
|
||
cv = [ClassVar[int]] | ||
|
||
@dataclass | ||
class C: | ||
CVS = [ClassVar[str]] | ||
a: cv[0] | ||
b: 'C' | ||
c: 'CVS[0]' | ||
x: 'ClassVar["int"]' | ||
y: 'ClassVar[C]' | ||
|
||
print() | ||
print(C.__annotations__) | ||
print(C.__dataclass_fields__) | ||
|
||
|
||
#print(get_type_hints(C)) |