Skip to content

Commit 54d7d3e

Browse files
committed
Fix errors related to corner cases of function aliases
1 parent 686c0cd commit 54d7d3e

File tree

3 files changed

+72
-11
lines changed

3 files changed

+72
-11
lines changed

bpystubgen/directives.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,7 @@ def run(self) -> List[Node]:
333333
alias_match = self._alias_pattern.match(ds.docstring.astext())
334334

335335
if alias_match:
336-
alias_text = alias_match.group(1)
337-
alias_text.replace(" and ", ", ")
336+
alias_text = alias_match.group(1).replace(" and ", ", ").replace(" or ", ", ")
338337

339338
for alias in map(lambda a: a.strip(), alias_text.split(",")):
340339
copy = elem.deepcopy()

tests/fixtures/stub/bgl/__init__.pyi

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,15 @@ for example.
147147
148148
:func:`glEvalMesh`
149149
150-
:func:`glEvalMesh1 or glEvalMesh2`
150+
:func:`glEvalMesh1`
151+
152+
:func:`glEvalMesh2`
151153
152154
:func:`glEvalPoint`
153155
154-
:func:`glEvalPoint1 and glEvalPoint2`
156+
:func:`glEvalPoint1`
157+
158+
:func:`glEvalPoint2`
155159
156160
:func:`glFeedbackBuffer`
157161
@@ -187,7 +191,9 @@ for example.
187191
188192
:func:`glGetLight`
189193
190-
:func:`glGetLightfv and glGetLightiv`
194+
:func:`glGetLightfv`
195+
196+
:func:`glGetLightiv`
191197
192198
:func:`glGetMap`
193199
@@ -1592,7 +1598,21 @@ def glEvalMesh(mode: typing.Any, i1: typing.Any, i2: typing.Any) -> None:
15921598

15931599
...
15941600

1595-
def glEvalMesh1 or glEvalMesh2(mode: typing.Any, i1: typing.Any, i2: typing.Any) -> None:
1601+
def glEvalMesh1(mode: typing.Any, i1: typing.Any, i2: typing.Any) -> None:
1602+
1603+
"""
1604+
1605+
B{glEvalMesh1 or glEvalMesh2}
1606+
1607+
Compute a one- or two-dimensional grid of points or lines
1608+
1609+
`OpenGL Docs <https://khronos.org/registry/OpenGL-Refpages/gl4/html/glEvalMesh.xhtml>`_
1610+
1611+
"""
1612+
1613+
...
1614+
1615+
def glEvalMesh2(mode: typing.Any, i1: typing.Any, i2: typing.Any) -> None:
15961616

15971617
"""
15981618
@@ -1620,7 +1640,21 @@ def glEvalPoint(i: int, j: int) -> None:
16201640

16211641
...
16221642

1623-
def glEvalPoint1 and glEvalPoint2(i: int, j: int) -> None:
1643+
def glEvalPoint1(i: int, j: int) -> None:
1644+
1645+
"""
1646+
1647+
B{glEvalPoint1 and glEvalPoint2}
1648+
1649+
Generate and evaluate a single point in a mesh
1650+
1651+
`OpenGL Docs <https://khronos.org/registry/OpenGL-Refpages/gl4/html/glEvalPoint.xhtml>`_
1652+
1653+
"""
1654+
1655+
...
1656+
1657+
def glEvalPoint2(i: int, j: int) -> None:
16241658

16251659
"""
16261660
@@ -1860,7 +1894,21 @@ def glGetLight(light: typing.Any, pname: typing.Any, params: Buffer) -> None:
18601894

18611895
...
18621896

1863-
def glGetLightfv and glGetLightiv(light: typing.Any, pname: typing.Any, params: Buffer) -> None:
1897+
def glGetLightfv(light: typing.Any, pname: typing.Any, params: Buffer) -> None:
1898+
1899+
"""
1900+
1901+
B{glGetLightfv and glGetLightiv}
1902+
1903+
Return light source parameter values
1904+
1905+
`OpenGL Docs <https://khronos.org/registry/OpenGL-Refpages/gl4/html/glGetLight.xhtml>`_
1906+
1907+
"""
1908+
1909+
...
1910+
1911+
def glGetLightiv(light: typing.Any, pname: typing.Any, params: Buffer) -> None:
18641912

18651913
"""
18661914

tests/test_function.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,14 +287,12 @@ def test_parse_bpy_prop_collection(parser: Parser, document: document):
287287
"bpy.types.bpy_prop_collection]"
288288

289289

290-
def test_parse_alias(parser: Parser, document: document):
290+
def test_parse_alias_comma(parser: Parser, document: document):
291291
source = """
292292
.. function:: glEvalCoord (u,v):
293293
294294
B{glEvalCoord1d, glEvalCoord1f, glEvalCoord2d, glEvalCoord2f, glEvalCoord1dv, glEvalCoord1fv,
295295
glEvalCoord2dv, glEvalCoord2fv}
296-
297-
Evaluate enabled one- and two-dimensional maps
298296
""".strip()
299297

300298
parser.parse(source, document)
@@ -306,6 +304,22 @@ def test_parse_alias(parser: Parser, document: document):
306304
"glEvalCoord2d", "glEvalCoord2dv", "glEvalCoord2f", "glEvalCoord2fv"}
307305

308306

307+
@mark.parametrize("conjunction", ("and", "or"))
308+
def test_parse_alias_conjunct(conjunction: str, parser: Parser, document: document):
309+
source = f"""
310+
.. function:: glEvalPoint (i, j):
311+
312+
B{{glEvalPoint1 {conjunction} glEvalPoint2}}
313+
""".strip()
314+
315+
parser.parse(source, document)
316+
document.transformer.apply_transforms()
317+
318+
functions = set(map(lambda f: f.name, document.traverse(Function)))
319+
320+
assert functions == {"glEvalPoint", "glEvalPoint1", "glEvalPoint2"}
321+
322+
309323
def test_parse_varargs(parser: Parser, document: document):
310324
source = """
311325
.. function:: app_template_paths(*, path=None)

0 commit comments

Comments
 (0)