[pydoclint] Implement docstring-missing-exception and `docstring-… · astral-sh/ruff@4bc73dd (original) (raw)

``

1

`+

import something

`

``

2

`+

from somewhere import AnotherError

`

``

3

+

``

4

+

``

5

`+

class FasterThanLightError(Exception):

`

``

6

`+

...

`

``

7

+

``

8

+

``

9

`+

_some_error = Exception

`

``

10

+

``

11

+

``

12

`+

OK

`

``

13

`+

def calculate_speed(distance: float, time: float) -> float:

`

``

14

`+

"""Calculate speed as distance divided by time.

`

``

15

+

``

16

`+

Args:

`

``

17

`+

distance: Distance traveled.

`

``

18

`+

time: Time spent traveling.

`

``

19

+

``

20

`+

Returns:

`

``

21

`+

Speed as distance divided by time.

`

``

22

+

``

23

`+

Raises:

`

``

24

`+

FasterThanLightError: If speed is greater than the speed of light.

`

``

25

`+

"""

`

``

26

`+

try:

`

``

27

`+

return distance / time

`

``

28

`+

except ZeroDivisionError as exc:

`

``

29

`+

raise FasterThanLightError from exc

`

``

30

+

``

31

+

``

32

`+

DOC501

`

``

33

`+

def calculate_speed(distance: float, time: float) -> float:

`

``

34

`+

"""Calculate speed as distance divided by time.

`

``

35

+

``

36

`+

Args:

`

``

37

`+

distance: Distance traveled.

`

``

38

`+

time: Time spent traveling.

`

``

39

+

``

40

`+

Returns:

`

``

41

`+

Speed as distance divided by time.

`

``

42

`+

"""

`

``

43

`+

try:

`

``

44

`+

return distance / time

`

``

45

`+

except ZeroDivisionError as exc:

`

``

46

`+

raise FasterThanLightError from exc

`

``

47

+

``

48

+

``

49

`+

DOC501

`

``

50

`+

def calculate_speed(distance: float, time: float) -> float:

`

``

51

`+

"""Calculate speed as distance divided by time.

`

``

52

+

``

53

`+

Args:

`

``

54

`+

distance: Distance traveled.

`

``

55

`+

time: Time spent traveling.

`

``

56

+

``

57

`+

Returns:

`

``

58

`+

Speed as distance divided by time.

`

``

59

`+

"""

`

``

60

`+

try:

`

``

61

`+

return distance / time

`

``

62

`+

except ZeroDivisionError as exc:

`

``

63

`+

raise FasterThanLightError from exc

`

``

64

`+

except:

`

``

65

`+

raise ValueError

`

``

66

+

``

67

+

``

68

`+

DOC501

`

``

69

`+

def calculate_speed(distance: float, time: float) -> float:

`

``

70

`+

"""Calculate speed as distance divided by time.

`

``

71

+

``

72

`+

Args:

`

``

73

`+

distance: Distance traveled.

`

``

74

`+

time: Time spent traveling.

`

``

75

+

``

76

`+

Returns:

`

``

77

`+

Speed as distance divided by time.

`

``

78

`+

"""

`

``

79

`+

try:

`

``

80

`+

return distance / time

`

``

81

`+

except ZeroDivisionError as exc:

`

``

82

`+

print('oops')

`

``

83

`+

raise exc

`

``

84

+

``

85

+

``

86

`+

DOC501

`

``

87

`+

def calculate_speed(distance: float, time: float) -> float:

`

``

88

`+

"""Calculate speed as distance divided by time.

`

``

89

+

``

90

`+

Args:

`

``

91

`+

distance: Distance traveled.

`

``

92

`+

time: Time spent traveling.

`

``

93

+

``

94

`+

Returns:

`

``

95

`+

Speed as distance divided by time.

`

``

96

`+

"""

`

``

97

`+

try:

`

``

98

`+

return distance / time

`

``

99

`+

except (ZeroDivisionError, ValueError) as exc:

`

``

100

`+

print('oops')

`

``

101

`+

raise exc

`

``

102

+

``

103

+

``

104

`+

DOC501

`

``

105

`+

def calculate_speed(distance: float, time: float) -> float:

`

``

106

`+

"""Calculate speed as distance divided by time.

`

``

107

+

``

108

`+

Args:

`

``

109

`+

distance: Distance traveled.

`

``

110

`+

time: Time spent traveling.

`

``

111

+

``

112

`+

Returns:

`

``

113

`+

Speed as distance divided by time.

`

``

114

`+

"""

`

``

115

`+

raise AnotherError

`

``

116

+

``

117

+

``

118

`+

DOC501

`

``

119

`+

def calculate_speed(distance: float, time: float) -> float:

`

``

120

`+

"""Calculate speed as distance divided by time.

`

``

121

+

``

122

`+

Args:

`

``

123

`+

distance: Distance traveled.

`

``

124

`+

time: Time spent traveling.

`

``

125

+

``

126

`+

Returns:

`

``

127

`+

Speed as distance divided by time.

`

``

128

`+

"""

`

``

129

`+

raise AnotherError()

`

``

130

+

``

131

+

``

132

`+

DOC501

`

``

133

`+

def foo(bar: int):

`

``

134

`+

"""Foo.

`

``

135

+

``

136

`+

Args:

`

``

137

`+

bar: Bar.

`

``

138

`+

"""

`

``

139

`+

raise something.SomeError

`

``

140

+

``

141

+

``

142

`+

DOC501, but can't resolve the error

`

``

143

`+

def calculate_speed(distance: float, time: float) -> float:

`

``

144

`+

"""Calculate speed as distance divided by time.

`

``

145

+

``

146

`+

Args:

`

``

147

`+

distance: Distance traveled.

`

``

148

`+

time: Time spent traveling.

`

``

149

+

``

150

`+

Returns:

`

``

151

`+

Speed as distance divided by time.

`

``

152

`+

"""

`

``

153

`+

raise _some_error

`

``

154

+

``

155

+

``

156

`+

OK

`

``

157

`+

def calculate_speed(distance: float, time: float) -> float:

`

``

158

`+

try:

`

``

159

`+

return distance / time

`

``

160

`+

except ZeroDivisionError as exc:

`

``

161

`+

raise FasterThanLightError from exc

`

``

162

+

``

163

+

``

164

`+

OK

`

``

165

`+

def calculate_speed(distance: float, time: float) -> float:

`

``

166

`+

raise NotImplementedError

`

``

167

+

``

168

+

``

169

`+

OK

`

``

170

`+

def foo(bar: int):

`

``

171

`+

"""Foo.

`

``

172

+

``

173

`+

Args:

`

``

174

`+

bar: Bar.

`

``

175

+

``

176

`+

Raises:

`

``

177

`+

SomeError: Wow.

`

``

178

`+

"""

`

``

179

`+

raise something.SomeError

`

``

180

+

``

181

+

``

182

`+

OK

`

``

183

`+

def foo(bar: int):

`

``

184

`+

"""Foo.

`

``

185

+

``

186

`+

Args:

`

``

187

`+

bar: Bar.

`

``

188

+

``

189

`+

Raises:

`

``

190

`+

something.SomeError: Wow.

`

``

191

`+

"""

`

``

192

`+

raise something.SomeError

`