Skip to content

Commit 85f799a

Browse files
committed
Replace Remove doc comments script with Ruff
1 parent 5ef1657 commit 85f799a

File tree

4 files changed

+39
-116
lines changed

4 files changed

+39
-116
lines changed

pyproject.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ ignore = [
4343
"PYI014",
4444
"PYI053",
4545

46-
# TODO: Handle in its own PR
47-
"PYI021", # https://github.com/microsoft/python-type-stubs/pull/343
48-
4946
# TODO: Investigate and fix or configure
5047
"PYI001",
5148
"PYI002",
@@ -57,6 +54,10 @@ ignore = [
5754
"PYI052",
5855
]
5956

57+
[tool.ruff.lint.per-file-ignores]
58+
# We keep docstrings in sklearn
59+
"stubs/sklearn/**" = ["PYI021"]
60+
6061
[tool.ruff.lint.isort]
6162
combine-as-imports = true
6263
extra-standard-library = [
@@ -67,7 +68,6 @@ extra-standard-library = [
6768

6869
[tool.pyright]
6970
exclude = ["build", ".git"]
70-
stubPath = "./stubs"
7171
# Target oldest supported Python version
7272
pythonversion = "3.9"
7373
typeCheckingMode = "standard"

stubs/matplotlib/ft2font.pyi

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,37 @@ FIXED_SIZES: int
1111
FIXED_WIDTH: int
1212

1313
class FT2Font(_mod_builtins.object):
14-
"Create a new FT2Font object.\n\nAttributes\n----------\nnum_faces\n Number of faces in file.\nface_flags, style_flags : int\n Face and style flags; see the ft2font constants.\nnum_glyphs\n Number of glyphs in the face.\nfamily_name, style_name\n Face family and style name.\nnum_fixed_sizes\n Number of bitmap in the face.\nscalable\n Whether face is scalable; attributes after this one are only\n defined for scalable faces.\nbbox\n Face global bounding box (xmin, ymin, xmax, ymax).\nunits_per_EM\n Number of font units covered by the EM.\nascender, descender\n Ascender and descender in 26.6 units.\nheight\n Height in 26.6 units; used to compute a default line spacing\n (baseline-to-baseline distance).\nmax_advance_width, max_advance_height\n Maximum horizontal and vertical cursor advance for all glyphs.\nunderline_position, underline_thickness\n Vertical position and thickness of the underline bar.\npostscript_name\n PostScript name of the font.\n"
14+
1515
def __init__(self, *args, **kwargs) -> None:
16-
"Create a new FT2Font object.\n\nAttributes\n----------\nnum_faces\n Number of faces in file.\nface_flags, style_flags : int\n Face and style flags; see the ft2font constants.\nnum_glyphs\n Number of glyphs in the face.\nfamily_name, style_name\n Face family and style name.\nnum_fixed_sizes\n Number of bitmap in the face.\nscalable\n Whether face is scalable; attributes after this one are only\n defined for scalable faces.\nbbox\n Face global bounding box (xmin, ymin, xmax, ymax).\nunits_per_EM\n Number of font units covered by the EM.\nascender, descender\n Ascender and descender in 26.6 units.\nheight\n Height in 26.6 units; used to compute a default line spacing\n (baseline-to-baseline distance).\nmax_advance_width, max_advance_height\n Maximum horizontal and vertical cursor advance for all glyphs.\nunderline_position, underline_thickness\n Vertical position and thickness of the underline bar.\npostscript_name\n PostScript name of the font.\n"
16+
1717
...
1818

1919
@classmethod
2020
def __init_subclass__(cls) -> None:
21-
"This method is called when a class is subclassed.\n\nThe default implementation does nothing. It may be\noverridden to extend subclasses.\n"
21+
2222
...
2323

2424
@classmethod
2525
def __subclasshook__(cls, subclass: typing.Any) -> bool:
26-
"Abstract classes can override this to customize issubclass().\n\nThis is invoked early on by abc.ABCMeta.__subclasscheck__().\nIt should return True, False or NotImplemented. If it returns\nNotImplemented, the normal algorithm is used. Otherwise, it\noverrides the normal algorithm (and the outcome is cached).\n"
26+
2727
...
2828

2929
@property
3030
def ascender(self) -> typing.Any: ...
3131
@property
3232
def bbox(self) -> typing.Any: ...
3333
def clear(self) -> typing.Any:
34-
"Clear all the glyphs, reset for a new call to `.set_text`.\n"
34+
3535
...
3636

3737
@property
3838
def descender(self) -> typing.Any: ...
3939
def draw_glyph_to_bitmap(self, bitmap, x, y, glyph) -> typing.Any:
40-
"Draw a single glyph to the bitmap at pixel locations x, y\nNote it is your responsibility to set up the bitmap manually\nwith ``set_bitmap_size(w, h)`` before this call is made.\n\nIf you want automatic layout, use `.set_text` in combinations with\n`.draw_glyphs_to_bitmap`. This function is instead intended for people\nwho want to render individual glyphs (e.g., returned by `.load_char`)\nat precise locations.\n"
40+
4141
...
4242

4343
def draw_glyphs_to_bitmap(self) -> typing.Any:
44-
"Draw the glyphs that were loaded by `.set_text` to the bitmap.\nThe bitmap size will be automatically set to include the glyphs.\n"
44+
4545
...
4646

4747
@property
@@ -51,73 +51,73 @@ class FT2Font(_mod_builtins.object):
5151
@property
5252
def fname(self) -> typing.Any: ...
5353
def get_bitmap_offset(self) -> typing.Any:
54-
"Get the (x, y) offset in 26.6 subpixels for the bitmap if ink hangs left or below (0, 0).\nSince Matplotlib only supports left-to-right text, y is always 0.\n"
54+
5555
...
5656

5757
def get_char_index(self, codepoint) -> typing.Any:
58-
"Return the glyph index corresponding to a character *codepoint*.\n"
58+
5959
...
6060

6161
def get_charmap(self) -> typing.Any:
62-
"Return a dict that maps the character codes of the selected charmap\n(Unicode by default) to their corresponding glyph indices.\n"
62+
6363
...
6464

6565
def get_descent(self) -> typing.Any:
66-
"Get the descent in 26.6 subpixels of the current string set by `.set_text`.\nThe rotation of the string is accounted for. To get the descent\nin pixels, divide this value by 64.\n"
66+
6767
...
6868

6969
def get_glyph_name(self, index) -> typing.Any:
70-
"Retrieve the ASCII name of a given glyph *index* in a face.\n\nDue to Matplotlib's internal design, for fonts that do not contain glyph\nnames (per FT_FACE_FLAG_GLYPH_NAMES), this returns a made-up name which\ndoes *not* roundtrip through `.get_name_index`.\n"
70+
7171
...
7272

7373
def get_image(self) -> typing.Any:
74-
"Return the underlying image buffer for this font object.\n"
74+
7575
...
7676

7777
def get_kerning(self, left, right, mode) -> typing.Any:
78-
"Get the kerning between *left* and *right* glyph indices.\n*mode* is a kerning mode constant:\n KERNING_DEFAULT - Return scaled and grid-fitted kerning distances\n KERNING_UNFITTED - Return scaled but un-grid-fitted kerning distances\n KERNING_UNSCALED - Return the kerning vector in original font units\n"
78+
7979
...
8080

8181
def get_name_index(self, name) -> typing.Any:
82-
"Return the glyph index of a given glyph *name*.\nThe glyph index 0 means 'undefined character code'.\n"
82+
8383
...
8484

8585
def get_num_glyphs(self) -> typing.Any:
86-
"Return the number of loaded glyphs.\n"
86+
8787
...
8888

8989
def get_path(self) -> typing.Any:
90-
"Get the path data from the currently loaded glyph as a tuple of vertices, codes.\n"
90+
9191
...
9292

9393
def get_ps_font_info(self) -> typing.Any:
94-
"Return the information in the PS Font Info structure.\n"
94+
9595
...
9696

9797
def get_sfnt(self) -> typing.Any:
98-
"Load the entire SFNT names table, as a dict whose keys are\n(platform-ID, ISO-encoding-scheme, language-code, and description)\ntuples.\n"
98+
9999
...
100100

101101
def get_sfnt_table(self, name) -> typing.Any:
102-
"Return one of the following SFNT tables: head, maxp, OS/2, hhea, vhea, post, or pclt.\n"
102+
103103
...
104104

105105
def get_width_height(self) -> typing.Any:
106-
"Get the width and height in 26.6 subpixels of the current string set by `.set_text`.\nThe rotation of the string is accounted for. To get width and height\nin pixels, divide these values by 64.\n"
106+
107107
...
108108

109109
def get_xys(self) -> typing.Any:
110-
"Get the xy locations of the current glyphs.\n"
110+
111111
...
112112

113113
@property
114114
def height(self) -> typing.Any: ...
115115
def load_char(self, charcode, flags) -> typing.Any:
116-
"Load character with *charcode* in current fontfile and set glyph.\n*flags* can be a bitwise-or of the LOAD_XXX constants;\nthe default value is LOAD_FORCE_AUTOHINT.\nReturn value is a Glyph object, with attributes\n width # glyph width\n height # glyph height\n bbox # the glyph bbox (xmin, ymin, xmax, ymax)\n horiBearingX # left side bearing in horizontal layouts\n horiBearingY # top side bearing in horizontal layouts\n horiAdvance # advance width for horizontal layout\n vertBearingX # left side bearing in vertical layouts\n vertBearingY # top side bearing in vertical layouts\n vertAdvance # advance height for vertical layout\n"
116+
117117
...
118118

119119
def load_glyph(self, glyphindex, flags) -> typing.Any:
120-
"Load character with *glyphindex* in current fontfile and set glyph.\n*flags* can be a bitwise-or of the LOAD_XXX constants;\nthe default value is LOAD_FORCE_AUTOHINT.\nReturn value is a Glyph object, with attributes\n width # glyph width\n height # glyph height\n bbox # the glyph bbox (xmin, ymin, xmax, ymax)\n horiBearingX # left side bearing in horizontal layouts\n horiBearingY # top side bearing in horizontal layouts\n horiAdvance # advance width for horizontal layout\n vertBearingX # left side bearing in vertical layouts\n vertBearingY # top side bearing in vertical layouts\n vertAdvance # advance height for vertical layout\n"
120+
121121
...
122122

123123
@property
@@ -137,19 +137,19 @@ class FT2Font(_mod_builtins.object):
137137
@property
138138
def scalable(self) -> typing.Any: ...
139139
def select_charmap(self, i) -> typing.Any:
140-
"Select a charmap by its FT_Encoding number.\n"
140+
141141
...
142142

143143
def set_charmap(self, i) -> typing.Any:
144-
"Make the i-th charmap current.\n"
144+
145145
...
146146

147147
def set_size(self, ptsize, dpi) -> typing.Any:
148-
"Set the point size and dpi of the text.\n"
148+
149149
...
150150

151151
def set_text(self, string, angle, flags) -> typing.Any:
152-
"Set the text *string* and *angle*.\n*flags* can be a bitwise-or of the LOAD_XXX constants;\nthe default value is LOAD_FORCE_AUTOHINT.\nYou must call this before `.draw_glyphs_to_bitmap`.\nA sequence of x,y positions is returned.\n"
152+
153153
...
154154

155155
@property
@@ -168,20 +168,20 @@ class FT2Image(_mod_builtins.object):
168168
def __init__(self, *args, **kwargs) -> None: ...
169169
@classmethod
170170
def __init_subclass__(cls) -> None:
171-
"This method is called when a class is subclassed.\n\nThe default implementation does nothing. It may be\noverridden to extend subclasses.\n"
171+
172172
...
173173

174174
@classmethod
175175
def __subclasshook__(cls, subclass: typing.Any) -> bool:
176-
"Abstract classes can override this to customize issubclass().\n\nThis is invoked early on by abc.ABCMeta.__subclasscheck__().\nIt should return True, False or NotImplemented. If it returns\nNotImplemented, the normal algorithm is used. Otherwise, it\noverrides the normal algorithm (and the outcome is cached).\n"
176+
177177
...
178178

179179
def draw_rect(self, x0, y0, x1, y1) -> typing.Any:
180-
"Draw an empty rectangle to the image.\n"
180+
181181
...
182182

183183
def draw_rect_filled(self, x0, y0, x1, y1) -> typing.Any:
184-
"Draw a filled rectangle to the image.\n"
184+
185185
...
186186

187187
def __getattr__(self, name) -> typing.Any: ...

stubs/sympy-stubs/README.md

Lines changed: 2 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ These stubs were generated by:
22

33
- Running `pyright --createstub sympy` after installing sympy into a venv
44
- Running a script that uncommented all of the return values in the generated stubs
5-
- Running a script that removed all doc strings from the stubs (as sympy has docstrings itself)
5+
- Running Ruff (`tests/run_hygiene.py`) to cleanup stubs and remove all doc strings from the stubs (as sympy has docstrings itself)
66
- Adding a `partial` py.typed file
7-
- Fixing all import errors one at a time (using Pylance)
7+
- Fixing all import errors one at a time (using Pylance and `tests/run_tests.py`)
88

99
The last part took the longest. It might be quicker to just add any changes by hand, rather than regenerating from scratch.
1010

11-
1211
Scripts for future use:
1312

1413
### Uncomment return values
@@ -78,79 +77,3 @@ def fix_all_stubs() -> None:
7877
fix_all_stubs()
7978

8079
```
81-
82-
### Remove doc comments
83-
```python
84-
85-
from codecs import ignore_errors
86-
import os
87-
import shutil
88-
from typing import List
89-
90-
91-
SOURCE_DIR = "typings\\sympy-returnvalues"
92-
DEST_DIR = "typings\\sympy-docs"
93-
94-
95-
def fix_file(file_path:str, dest_path:str):
96-
# Read the file one char at a time until we find one of r""", b""", or """
97-
with open(file_path, mode="r") as file:
98-
lines = file.readlines()
99-
contents = "".join(lines)
100-
new_contents = ""
101-
in_docstring = False
102-
ignoring_line = False
103-
line_start = 0
104-
i = 0
105-
while i < len(contents):
106-
char = contents[i]
107-
if contents[i] == "\n":
108-
line_start = len(new_contents)
109-
if ignoring_line and not in_docstring:
110-
ignoring_line = False
111-
112-
if contents[i:i+3] == "\"\"\"" or contents[i:i+3] == "\'\'\'":
113-
in_docstring = not in_docstring
114-
new_contents = new_contents[:line_start]
115-
ignoring_line = True
116-
i += 3
117-
elif contents[i:i+4] == "r\"\"\"" or contents[i:i+4] == "r\'\'\'" and not in_docstring:
118-
in_docstring = True
119-
new_contents = new_contents[:line_start]
120-
ignoring_line = True
121-
i += 4
122-
elif not in_docstring and not ignoring_line:
123-
new_contents += char
124-
i += 1
125-
else:
126-
i += 1
127-
try:
128-
os.makedirs(os.path.dirname(dest_path))
129-
except FileExistsError:
130-
pass
131-
132-
print(f"Writing {dest_path}")
133-
with open(dest_path, mode="w") as file:
134-
file.write(new_contents)
135-
136-
137-
def fix_all_stubs() -> None:
138-
stubs_dir = SOURCE_DIR
139-
dest_dir = DEST_DIR
140-
shutil.rmtree(dest_dir, ignore_errors=True)
141-
os.makedirs(dest_dir, exist_ok=True)
142-
143-
# Then iterate over all of the generated files and fix them up so they're valid
144-
for root, dirs, files in os.walk(stubs_dir):
145-
for file in files:
146-
if file.endswith(".pyi"):
147-
file_path = os.path.join(root, file)
148-
dest_path = file_path.replace(stubs_dir, dest_dir)
149-
sub_dir_pos = root.index(stubs_dir) + len(stubs_dir) + 1
150-
sub_dir = root[sub_dir_pos:]
151-
sub_package = sub_dir.replace("\\", ".")
152-
fix_file(file_path, dest_path)
153-
154-
fix_all_stubs()
155-
```
156-

stubs/sympy-stubs/matrices/sparse.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class SparseRepMatrix(RepMatrix):
1212
def nnz(self) -> int: ...
1313
def row_list(self) -> list[tuple[Any, ...]]: ...
1414
def scalar_multiply(self, scalar):
15-
"Scalar element-wise multiplication"
15+
1616
...
1717

1818
def solve_least_squares(self, rhs, method=...): ...

0 commit comments

Comments
 (0)