8000 gh-85455: Add missing doc strings and improve docs (#21573) · python/cpython@bf786e6 · GitHub
[go: up one dir, main page]

Skip to content

Commit bf786e6

Browse files
gh-85455: Add missing doc strings and improve docs (#21573)
* Add missing doc strings and improve docs * Use imperative form * Modify docstring wording
1 parent 05c042e commit bf786e6

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

Doc/library/imghdr.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ The :mod:`imghdr` module defines the following function:
2121

2222
.. function:: what(file, h=None)
2323

24-
Tests the image data contained in the file named by *file*, and returns a
25-
string describing the image type. If optional *h* is provided, the *file*
24+
Test the image data contained in the file named *file* and return a
25+
string describing the image type. If *h* is provided, the *file*
2626
argument is ignored and *h* is assumed to contain the byte stream to test.
2727

2828
.. versionchanged:: 3.6

Lib/imghdr.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#-------------------------#
1515

1616
def what(file, h=None):
17+
"""Return the type of image contained in a file or byte stream."""
1718
f = None
1819
try:
1920
if h is None:
@@ -40,7 +41,7 @@ def what(file, h=None):
4041
tests = []
4142

4243
def test_jpeg(h, f):
43-
"""JPEG data with JFIF or Exif markers; and raw JPEG"""
44+
"""Test for JPEG data with JFIF or Exif markers; and raw JPEG."""
4445
if h[6:10] in (b'JFIF', b'Exif'):
4546
return 'jpeg'
4647
elif h[:4] == b'\xff\xd8\xff\xdb':
@@ -49,83 +50,87 @@ def test_jpeg(h, f):
4950
tests.append(test_jpeg)
5051

5152
def test_png(h, f):
53+
"""Verify if the image is a PNG."""
5254
if h.startswith(b'\211PNG\r\n\032\n'):
5355
return 'png'
5456

5557
tests.append(test_png)
5658

5759
def test_gif(h, f):
58-
"""GIF ('87 and '89 variants)"""
60+
"""Verify if the image is a GIF ('87 or '89 variants)."""
5961
if h[:6] in (b'GIF87a', b'GIF89a'):
6062
return 'gif'
6163

6264
tests.append(test_gif)
6365

6466
def test_tiff(h, f):
65-
"""TIFF (can be in Motorola or Intel byte order)"""
67+
"""Verify if the image is a TIFF (can be in Motorola or Intel byte order)."""
6668
if h[:2] in (b'MM', b'II'):
6769
return 'tiff'
6870

6971
tests.append(test_tiff)
7072

7173
def test_rgb(h, f):
72-
"""SGI image library"""
74+
"""test for the SGI image library."""
7375
if h.startswith(b'\001\332'):
7476
return 'rgb'
7577

7678
tests.append(test_rgb)
7779

7880
def test_pbm(h, f):
79-
"""PBM (portable bitmap)"""
81+
"""Verify if the image is a PBM (portable bitmap)."""
8082
if len(h) >= 3 and \
8183
h[0] == ord(b'P') and h[1] in b'14' and h[2] in b' \t\n\r':
8284
return 'pbm'
8385

8486
tests.append(test_pbm)
8587

8688
def test_pgm(h, f):
87-
"""PGM (portable graymap)"""
89+
"""Verify if the image is a PGM (portable graymap)."""
8890
if len(h) >= 3 and \
8991
h[0] == ord(b'P') and h[1] in b'25' and h[2] in b' \t\n\r':
9092
return 'pgm'
9193

9294
tests.append(test_pgm)
9395

9496
def test_ppm(h, f):
95-
"""PPM (portable pixmap)"""
97+
"""Verify if the image is a PPM (portable pixmap)."""
9698
if len(h) >= 3 and \
9799
h[0] == ord(b'P') and h[1] in b'36' and h[2] in b' \t\n\r':
98100
return 'ppm'
99101

100102
tests.append(test_ppm)
101103

102104
def test_rast(h, f):
103-
"""Sun raster file"""
105+
"""test for the Sun raster file."""
104106
if h.startswith(b'\x59\xA6\x6A\x95'):
105107
return 'rast'
106108

107109
tests.append(test_rast)
108110

109111
def test_xbm(h, f):
110-
"""X bitmap (X10 or X11)"""
112+
"""Verify if the image is a X bitmap (X10 or X11)."""
111113
if h.startswith(b'#define '):
112114
return 'xbm'
113115

114116
tests.append(test_xbm)
115117

116118
def test_bmp(h, f):
119+
"""Verify if the image is a BMP file."""
117120
if h.startswith(b'BM'):
118121
return 'bmp'
119122

120123
tests.append(test_bmp)
121124

122125
def test_webp(h, f):
126+
"""Verify if the image is a WebP."""
123127
if h.startswith(b'RIFF') and h[8:12] == b'WEBP':
124128
return 'webp'
125129

126130
tests.append(test_webp)
127131

128132
def test_exr(h, f):
133+
"""verify is the image ia a OpenEXR fileOpenEXR."""
129134
if h.startswith(b'\x76\x2f\x31\x01'):
130135
return 'exr'
131136

0 commit comments

Comments
 (0)
0