Skip to content

Commit 2ffb0ac

Browse files
committed
actually submit the add
1 parent acc937f commit 2ffb0ac

File tree

528 files changed

+43444
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

528 files changed

+43444
-0
lines changed

stubs/sympy-stubs/README.md

+156
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
These stubs were generated by:
2+
3+
- Running `pyright --createstub sympy` after installing sympy into a venv
4+
- 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)
6+
- Adding a `partial` py.typed file
7+
- Fixing all import errors one at a time (using Pylance)
8+
9+
The last part took the longest. It might be quicker to just add any changes by hand, rather than regenerating from scratch.
10+
11+
12+
Scripts for future use:
13+
14+
### Uncomment return values
15+
16+
```python
17+
import os
18+
import re
19+
import shutil
20+
from typing import List
21+
22+
SOURCE_DIR = "typings\\sympy"
23+
DEST_DIR = "typings\\sympy-returnvalues"
24+
25+
def read_file(file_path: str) -> List[str]:
26+
with open(file_path, "r") as file:
27+
return file.readlines()
28+
29+
def write_file(file_path: str, lines: List[str]) -> None:
30+
try:
31+
os.makedirs(os.path.dirname(file_path))
32+
except FileExistsError:
33+
pass
34+
with open(file_path, "w") as file:
35+
file.writelines(lines)
36+
37+
def fix_file(file_path: str, dest_path: str, sub_package: str) -> None:
38+
lines = read_file(file_path)[4:]
39+
40+
# Turn the return type comments into actual return types
41+
changed = [re.sub(r":\s+#(.*)", r"\1", line) for line in lines]
42+
43+
# Replace `from .` imports with `from sympy.<subpackage>.`
44+
replace_str = f"from sympy.{sub_package + '.' if sub_package else ''}"
45+
changed = [re.sub(r"from \.", replace_str, line) for line in changed]
46+
any_changes = [line for line in changed if line not in lines]
47+
48+
if len(any_changes) > 0:
49+
# Find this same file in the '.venv/lib/site-packages/sympy' directory and see if it has typing information in it.
50+
site_packages_file = file_path.replace(SOURCE_DIR, ".venv\\lib\\site-packages\\sympy").replace(".pyi", ".py")
51+
if os.path.exists(site_packages_file):
52+
site_packages_lines = read_file(site_packages_file)
53+
if "->" in site_packages_lines:
54+
return
55+
else:
56+
print(f"Writing {dest_path}")
57+
write_file(dest_path, changed)
58+
59+
def fix_all_stubs() -> None:
60+
stubs_dir = SOURCE_DIR
61+
dest_dir = DEST_DIR
62+
shutil.rmtree(dest_dir, ignore_errors=True)
63+
os.makedirs(dest_dir, exist_ok=True)
64+
# First write a partial py.typed file to the destination directory
65+
write_file(os.path.join(dest_dir, "py.typed"), ["partial"])
66+
67+
# Then iterate over all of the generated files and fix them up so they're valid
68+
for root, dirs, files in os.walk(stubs_dir):
69+
for file in files:
70+
if file.endswith(".pyi"):
71+
file_path = os.path.join(root, file)
72+
dest_path = file_path.replace(stubs_dir, dest_dir)
73+
sub_dir_pos = root.index(stubs_dir) + len(stubs_dir) + 1
74+
sub_dir = root[sub_dir_pos:]
75+
sub_package = sub_dir.replace("\\", ".")
76+
fix_file(file_path, dest_path, sub_package)
77+
78+
fix_all_stubs()
79+
80+
```
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/__init__.pyi

+38
Large diffs are not rendered by default.
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from sympy.algebras.quaternion import Quaternion
2+
3+
__all__ = ["Quaternion"]
+173
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
from types import NotImplementedType
2+
from typing import Any, Literal, Self
3+
from sympy.core.basic import Basic
4+
from sympy.core.expr import Expr
5+
from sympy.core.function import UndefinedFunction
6+
from sympy.core.power import Pow
7+
from sympy.matrices.dense import MutableDenseMatrix
8+
9+
class Quaternion(Expr):
10+
_op_priority = ...
11+
is_commutative = ...
12+
def __new__(cls, a=..., b=..., c=..., d=..., real_field=..., norm=...) -> Self:
13+
...
14+
15+
def set_norm(self, norm) -> None:
16+
...
17+
18+
@property
19+
def a(self):
20+
...
21+
22+
@property
23+
def b(self):
24+
...
25+
26+
@property
27+
def c(self):
28+
...
29+
30+
@property
31+
def d(self):
32+
...
33+
34+
@property
35+
def real_field(self):
36+
...
37+
38+
@property
39+
def product_matrix_left(self) -> MutableDenseMatrix:
40+
...
41+
42+
@property
43+
def product_matrix_right(self) -> MutableDenseMatrix:
44+
...
45+
46+
def to_Matrix(self, vector_only=...) -> MutableDenseMatrix:
47+
...
48+
49+
@classmethod
50+
def from_Matrix(cls, elements) -> Quaternion:
51+
...
52+
53+
@classmethod
54+
def from_euler(cls, angles, seq) -> Any:
55+
...
56+
57+
def to_euler(self, seq, angle_addition=..., avoid_square_root=...) -> tuple[int, ...]:
58+
...
59+
60+
@classmethod
61+
def from_axis_angle(cls, vector, angle) -> Self:
62+
...
63+
64+
@classmethod
65+
def from_rotation_matrix(cls, M) -> Quaternion:
66+
...
67+
68+
def __add__(self, other) -> Quaternion:
69+
...
70+
71+
def __radd__(self, other) -> Quaternion:
72+
...
73+
74+
def __sub__(self, other) -> Quaternion:
75+
...
76+
77+
def __mul__(self, other) -> Quaternion:
78+
...
79+
80+
def __rmul__(self, other) -> Quaternion:
81+
...
82+
83+
def __pow__(self, p) -> NotImplementedType | Quaternion | Literal[1]:
84+
...
85+
86+
def __neg__(self) -> Quaternion:
87+
...
88+
89+
def __truediv__(self, other):
90+
...
91+
92+
def __rtruediv__(self, other):
93+
...
94+
95+
def diff(self, *symbols, **kwargs) -> Self:
96+
...
97+
98+
def add(self, other) -> Quaternion:
99+
...
100+
101+
def mul(self, other) -> Quaternion:
102+
...
103+
104+
def norm(self) -> Pow:
105+
...
106+
107+
def normalize(self):
108+
...
109+
110+
def inverse(self):
111+
...
112+
113+
def pow(self, p) -> NotImplementedType | Quaternion | Literal[1]:
114+
...
115+
116+
def exp(self) -> Quaternion:
117+
...
118+
119+
def pow_cos_sin(self, p):
120+
...
121+
122+
def integrate(self, *args) -> Quaternion:
123+
...
124+
125+
@staticmethod
126+
def rotate_point(pin, r) -> tuple[Any, Any, Any]:
127+
...
128+
129+
def to_axis_angle(self) -> tuple[tuple[Any, Any, Any], Any]:
130+
...
131+
132+
def to_rotation_matrix(self, v=..., homogeneous=...) -> MutableDenseMatrix:
133+
...
134+
135+
def scalar_part(self):
136+
...
137+
138+
def vector_part(self) -> Quaternion:
139+
...
140+
141+
def axis(self) -> Quaternion:
142+
...
143+
144+
def is_pure(self):
145+
...
146+
147+
def is_zero_quaternion(self) -> bool | None:
148+
...
149+
150+
def angle(self) -> type[UndefinedFunction]:
151+
...
152+
153+
def arc_coplanar(self, other) -> bool | None:
154+
...
155+
156+
@classmethod
157+
def vector_coplanar(cls, q1, q2, q3) -> Any | bool | None:
158+
...
159+
160+
def parallel(self, other):
161+
...
162+
163+
def orthogonal(self, other):
164+
...
165+
166+
def index_vector(self) -> Quaternion:
167+
...
168+
169+
def mensor(self) -> type[UndefinedFunction]:
170+
...
171+
172+
173+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from sympy.assumptions.assume import AppliedPredicate, AssumptionsContext, Predicate, assuming, global_assumptions
2+
from sympy.assumptions.ask import Q, ask, register_handler, remove_handler
3+
from sympy.assumptions.refine import refine
4+
from sympy.assumptions.relation import AppliedBinaryRelation, BinaryRelation
5+
6+
__all__ = ['AppliedPredicate', 'Predicate', 'AssumptionsContext', 'assuming', 'global_assumptions', 'Q', 'ask', 'register_handler', 'remove_handler', 'refine', 'BinaryRelation', 'AppliedBinaryRelation']

0 commit comments

Comments
 (0)