Wie bezeichne ich die Rückgabeart eines @classMethod ctor in Python? [Duplikat]Python

Python-Programme
Anonymous
 Wie bezeichne ich die Rückgabeart eines @classMethod ctor in Python? [Duplikat]

Post by Anonymous »

#!/usr/bin/env python

# In this file: a problem with de-serializing an object.

import pickle

class User:
@classmethod
def from_bytes(cls, b: bytes) -> User:
obj = pickle.loads(b)
assert type(obj) == cls, (type(obj), cls)
return obj
< /code>
fällt mit < /p>
fehlTraceback (most recent call last):
File "/tmp/./lqlq.py", line 7, in
class User:
......
return obj
File "/tmp/./lqlq.py", line 9, in User
def from_bytes(cls, b: bytes) -> User:
^^^^
NameError: name 'User' is not defined
< /code>
In C machen Sie eine Vorwärtsdeklaration. Was ist die Alternative in Python?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post