[issue42503] Cannot declare method or static function parameter or return type as self of the class

2020-11-29 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

You can already write such code in 3.10. In earlier Python versions you can 
either write annotation explicitly as string or (since 3.7) use and import 
suggested by Irit.

--
nosy: +serhiy.storchaka
resolution:  -> out of date
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42503] Cannot declare method or static function parameter or return type as self of the class

2020-11-29 Thread Irit Katriel


Irit Katriel  added the comment:

Add at the top of your script:

from __future__ import annotations

--
nosy: +iritkatriel

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42503] Cannot declare method or static function parameter or return type as self of the class

2020-11-29 Thread parsa mpsh


New submission from parsa mpsh :

python raises error `Undefined class X` when you declaring parameter type or 
return type of method as the self of class:

class MyClass:
def mymethod(self, a: MyClass): # parameter type is class self
pass

# or

class MyClass:
def mymethod(self) -> MyClass: # return type is class self
pass
# or both of them

error `Undefined class ...` will be raised.

--
messages: 382061
nosy: parsampsh
priority: normal
severity: normal
status: open
title: Cannot declare method or static function parameter or return type as 
self of the class
type: behavior
versions: Python 3.10, Python 3.6, Python 3.7, Python 3.8, Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com