title: Python - static method in class creating instance of that class
body: <p>I have Python data class created from JSON (quite a lot of them actually). I want to have a method for creating class instance from JSON.</p>
  <p>I have something like this:</p>
  <pre><code>class FromJSONMixin:
      @staticmethod
      @abstractmethod
      def from_json(json: Union[Dict, TypedDict], **kwargs):
          raise NotImplementedError
  
  
  class PatientJSON(TypedDict):
      ID: str
      Name: str
      Description: str
      BirthDate: str
  
  
  @dataclass
  class Patient(FromJSONMixin):
      name: str
      birth_date: str
      description: str
  
      @staticmethod
      def from_json(json: PatientJSON, **kwargs) -&gt; Patient:
          return Patient(
          name=json[&quot;Name&quot;],
          birth_date=json[&quot;BirthDate&quot;],
          description=raw_data[&quot;Description&quot;])
  </code></pre>
  <p>I want to create <code>Patient</code> objects from <code>PatientJSON</code> (the structure is related to the existing database, I have to integrate with it; it also does a few name-attribute translations, as you can see above). I created the <code>FromJSONMixin</code> to explicitly mark classes that can be created from related classes for JSONs (like <code>PatientJSON</code>).</p>
  <p><strong>Question:</strong> I get an error with the <code>-&gt; Patient:</code> part, <code>Unresolved reference 'Patient'</code>. Why? I can't type class objects in methods in the same class? Do I have to just give up on typing the return type?</p>