← Back to DAGDA | Support | Source: https://github.com/ambv/static-annotations/commit/441357d4a7e1d0609fff873854a61a0a003dac36
Skip to content
This repository was archived by the owner on Jun 22, 2020. It is now read-only.

Commit 441357d

Browse files
committed
Correct the nested class attribute access example
1 parent f23c72f commit 441357d

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

‎pep-0563.rst‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,20 +236,33 @@ valid. They can use local names or the fully qualified name. Example::
236236

237237
class C:
238238
field = 'c_field'
239-
def method(self, arg: C.field) -> None: # this is OK
239+
def method(self) -> C.field: # this is OK
240+
...
241+
242+
def method(self) -> field: # this is OK
243+
...
244+
245+
def method(self) -> C.D: # this is OK
246+
...
247+
248+
def method(self) -> D: # this is OK
240249
...
241250

242251
class D:
243252
field2 = 'd_field'
244-
def method(self, arg: C.field) -> C.D.field2: # this is OK
253+
def method(self) -> C.D.field2: # this is OK
245254
...
246255

247-
def method(self, arg: field) -> D.field2: # this is OK
256+
def method(self) -> D.field2: # this is OK
248257
...
249258

250-
def method(self, arg: field) -> field2: # this is OK
259+
def method(self) -> field2: # this is OK
251260
...
252261

262+
def method(self) -> field: # this FAILS, class D doesn't
263+
... # see C's attributes, This was
264+
# already true before this PEP.
265+
253266
In the presence of an annotation that isn't a syntactically valid
254267
expression, SyntaxError is raised at compile time. However, since names
255268
aren't resolved at that time, no attempt is made to validate whether

0 commit comments

Comments
 (0)