1
2
3
4
5
class classname(object):
"""
docstring
"""
pass
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
class object:
__doc__: str | None
__dict__: dict[str, Any]
__module__: str
__annotations__: dict[str, Any]
@property
def __class__(self) -> type[Self]: ...
# Ignore errors about type mismatch between property getter and setter
@__class__.setter
def __class__(self, __type: type[object]) -> None: ... # noqa: F811
def __init__(self) -> None: ...
def __new__(cls) -> Self: ...
# N.B. `object.__setattr__` and `object.__delattr__` are heavily special-cased by type checkers.
# Overriding them in subclasses has different semantics, even if the override has an identical signature.
def __setattr__(self, __name: str, __value: Any) -> None: ...
def __delattr__(self, __name: str) -> None: ...
def __eq__(self, __value: object) -> bool: ...
def __ne__(self, __value: object) -> bool: ...
def __str__(self) -> str: ... # noqa: Y029
def __repr__(self) -> str: ... # noqa: Y029
def __hash__(self) -> int: ...
def __format__(self, __format_spec: str) -> str: ...
def __getattribute__(self, __name: str) -> Any: ...
def __sizeof__(self) -> int: ...
# return type of pickle methods is rather hard to express in the current type system
# see #6661 and https://docs.python.org/3/library/pickle.html#object.__reduce__
def __reduce__(self) -> str | tuple[Any, ...]: ...
if sys.version_info >= (3, 8):
def __reduce_ex__(self, __protocol: SupportsIndex) -> str | tuple[Any, ...]: ...
else:
def __reduce_ex__(self, __protocol: int) -> str | tuple[Any, ...]: ...
if sys.version_info >= (3, 11):
def __getstate__(self) -> object: ...

def __dir__(self) -> Iterable[str]: ...
def __init_subclass__(cls) -> None: ...
@classmethod
def __subclasshook__(cls, __subclass: type) -> bool: ...

__doc__: str | None

__doc__方法是python内置方法之一,该方法通常会返回指定对象中的注释部分:

1
2
3
4
5
6
7
8
9
10
11
12
 
class ClassName:
'''
这个是我定义的类的注释
'''
def __init__(self):
'''
这是一个类属性
'''
index = ClassName()
print(index.__doc__)
print(index.__init__.__doc__)

__dict__: dict[str, Any]

__dict__属性在不同的地方有不同的使用:

  • __dict__属性:包括静态函数、普通函数、类函数或者全局变量、一些内置属性
  • 类对象__dict__属性:存储了一些self.xxx的一些东西,其中父类与子类对象共用__dict__
  • 在字典中是一个字典里面存放的数据
  • 一些内置数据类型是没有__dict__属性的。比如intlistdict等这些数据类型
  • 继承的时候__dict__属性中每个类的类变量,函数名都放在自己的__dict__中,实例变量的__dict__中父类和子类对象的__dict__是公用的

__module__: str

__annotations__: dict[str, Any]

def __class__(self, __type: type[object]) -> None: ... # noqa: F811

def __init__(self) -> None: ...

def __new__(cls) -> Self: ...

def __setattr__(self, __name: str, __value: Any) -> None: ...

def __delattr__(self, __name: str) -> None: ...

def __eq__(self, __value: object) -> bool: ...

def __ne__(self, __value: object) -> bool: ...

def __str__(self) -> str: ... # noqa: Y029

def __repr__(self) -> str: ... # noqa: Y029

def __hash__(self) -> int: ...

def __format__(self, __format_spec: str) -> str: ...

def __getattribute__(self, __name: str) -> Any: ...

def __sizeof__(self) -> int: ...

def __reduce__(self) -> str | tuple[Any, ...]: ...

def __dir__(self) -> Iterable[str]: ...

def __init_subclass__(cls) -> None: ...