class Session:
@staticmethod
def load_from_json(json_path:str) -> Session:
pass
Above throws a NameError: name 'Session' is not defined
.
Is using itself for the type hint in its definition impossible?
class Session:
@staticmethod
def load_from_json(json_path:str) -> Session:
pass
Above throws a NameError: name 'Session' is not defined
.
Is using itself for the type hint in its definition impossible?
Use:
def ... -> 'Session':
Session is not defined when you use it, so you must use a string (Python 3.8).
To construct the class instance:
class Session:
def __init__(self,json_path: str) -> None:
do stuff...
Feel free to correct me if I'm misunderstanding anything