class_docstr: Drop-in replacement for @classmethod, but raises an exception when the decorated method is called on an instance
  instead of a class type.
class_docstr_tok: ["Drop-in","replacement","for","@","classmethod",",","but","raises","an","exception","when","the","decorated","method","is","called","on","an","instance","instead","of","a","class","type","."]
code: def __get__(
      self, instance: Optional[_T], cls: Type[_T]
  ) -> Callable[_P, _R_co]:
      # Workaround for https://github.com/pytorch/pytorch/issues/67146
      is_scripting = any(
          os.path.join("torch", "jit") in frameinfo.filename
          for frameinfo in inspect.stack()
      )
      if instance is not None and not is_scripting:
          raise TypeError(
              f"The classmethod `{cls.__name__}.{self.method.__name__}` cannot be called on an instance."
              " Please call it on the class type and make sure the return value is used."
          )
      return MethodType(self.method, cls)
  
file_path: pytorch-lightning/src/lightning/pytorch/utilities/model_helpers.py
imports: import inspect
  import logging
  import os
  from types import MethodType
  from typing import TYPE_CHECKING, Any, Callable, Dict, Generic, Optional, Type, TypeVar
  from lightning_utilities.core.imports import RequirementCache
  from torch import nn
  from typing_extensions import Concatenate, ParamSpec
  import lightning.pytorch
label_desc: Use image node_id 2 for calling the _restricted_classmethod_impl obj's underlying member method code with example usage: obj.__get__(instance, cls) and returns: MethodType