Skip to content
This repository has been archived by the owner on Sep 15, 2024. It is now read-only.

Commit

Permalink
Handle case when module source exists without valid members
Browse files Browse the repository at this point in the history
Fixes the problem with Blender 2.8x API.
  • Loading branch information
mysticfall committed Sep 22, 2021
1 parent c3898fa commit 151c8b1
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 30 deletions.
17 changes: 16 additions & 1 deletion bpystubgen/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,22 @@ def parse(self, settings: Values, env: BuildEnvironment) -> Optional[document]:

self.doctree = doctree

module = next(iter(doctree.traverse(Module)))
try:
module = next(iter(doctree.traverse(Module)))
except StopIteration:
module = Module(name=self.full_name)

docstring = DocString()

for child in tuple(doctree.children):
doctree.remove(child)
docstring += child

module += docstring

doctree += patches.apply(self.full_name, module, settings, env)

doctree.transformer.apply_transforms()

for cls in module.traverse(Class):
patches.apply(cls.full_name, cls, settings, env)
Expand Down
54 changes: 26 additions & 28 deletions tests/fixtures/stub/bge/types.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import logging

import bpy

import bge

class KX_GameObject(bge.types.SCA_IObject):
class KX_GameObject(SCA_IObject):

"""
Expand Down Expand Up @@ -181,23 +179,23 @@ A value of 0.0 disables clamping; it does not stop rotation.
"""

parent: bge.types.KX_GameObject = ...
parent: KX_GameObject = ...

"""
The object's parent object. (read-only).
"""

groupMembers: typing.Union[typing.Sequence[bge.KX_GameObject], typing.Mapping[str, bge.KX_GameObject], bge.types.EXP_ListValue] = ...
groupMembers: typing.Union[typing.Sequence[KX_GameObject], typing.Mapping[str, KX_GameObject], bge.types.EXP_ListValue] = ...

"""
Returns the list of group members if the object is a group object (dupli group instance), otherwise None is returned.
"""

groupObject: bge.types.KX_GameObject = ...
groupObject: KX_GameObject = ...

"""
Expand Down Expand Up @@ -274,7 +272,7 @@ used.
"""

scene: bge.types.KX_Scene = ...
scene: KX_Scene = ...

"""
Expand All @@ -300,7 +298,7 @@ used.
"""

cullingBox: bge.types.KX_BoundingBox = ...
cullingBox: KX_BoundingBox = ...

"""
Expand Down Expand Up @@ -504,7 +502,7 @@ used.
"""

batchGroup: bge.types.KX_BatchGroup = ...
batchGroup: KX_BatchGroup = ...

"""
Expand Down Expand Up @@ -556,23 +554,23 @@ used.
"""

components: typing.Union[typing.Sequence[bge.KX_PythonComponent], typing.Mapping[str, bge.KX_PythonComponent], bge.types.EXP_ListValue] = ...
components: typing.Union[typing.Sequence[KX_PythonComponent], typing.Mapping[str, KX_PythonComponent], bge.types.EXP_ListValue] = ...

"""
All python components.
"""

children: typing.Union[typing.Sequence[bge.KX_GameObject], typing.Mapping[str, bge.KX_GameObject], bge.types.EXP_ListValue] = ...
children: typing.Union[typing.Sequence[KX_GameObject], typing.Mapping[str, KX_GameObject], bge.types.EXP_ListValue] = ...

"""
direct children of this object, (read-only).
"""

childrenRecursive: typing.Union[typing.Sequence[bge.KX_GameObject], typing.Mapping[str, bge.KX_GameObject], bge.types.EXP_ListValue] = ...
childrenRecursive: typing.Union[typing.Sequence[KX_GameObject], typing.Mapping[str, KX_GameObject], bge.types.EXP_ListValue] = ...

"""
Expand Down Expand Up @@ -612,7 +610,7 @@ used.
"""

lodManager: bge.types.KX_LodManager = ...
lodManager: KX_LodManager = ...

"""
Expand Down Expand Up @@ -976,7 +974,7 @@ Otherwise, only linear momentum will change.

...

def setParent(self, parent: bge.types.KX_GameObject, compound: bool = True, ghost: bool = True) -> None:
def setParent(self, parent: KX_GameObject, compound: bool = True, ghost: bool = True) -> None:

"""
Expand Down Expand Up @@ -1021,11 +1019,11 @@ Control the shape status with the optional compound and ghost parameters:

...

def getDistanceTo(self, other: typing.Union[bge.KX_GameObject, typing.List[typing.Any]]) -> float:
def getDistanceTo(self, other: typing.Union[KX_GameObject, typing.List[typing.Any]]) -> float:

...

def getVectTo(self, other: typing.Union[bge.KX_GameObject, typing.List[typing.Any]]) -> typing.Any:
def getVectTo(self, other: typing.Union[KX_GameObject, typing.List[typing.Any]]) -> typing.Any:

"""
Expand All @@ -1036,7 +1034,7 @@ The vector is normalized unless the distance is 0, in which a zero length vector

...

def rayCastTo(self, other: bge.types.KX_GameObject, dist: float = 0, prop: str = '') -> bge.types.KX_GameObject:
def rayCastTo(self, other: KX_GameObject, dist: float = 0, prop: str = '') -> KX_GameObject:

"""
Expand All @@ -1050,7 +1048,7 @@ Use rayCast() if you need to retrieve the hit point

...

def rayCast(self, objto: bge.types.KX_GameObject, objfrom: bge.types.KX_GameObject = None, dist: float = 0, prop: str = '', face: int = False, xray: int = False, poly: int = 0, mask: typing.Any = 65535) -> typing.Any:
def rayCast(self, objto: KX_GameObject, objfrom: KX_GameObject = None, dist: float = 0, prop: str = '', face: int = False, xray: int = False, poly: int = 0, mask: typing.Any = 65535) -> typing.Any:

"""
Expand Down Expand Up @@ -1237,7 +1235,7 @@ If there is no hit or the hit object is not a static mesh, None is returned as 4

...

class KX_PythonComponent(bge.types.EXP_Value):
class KX_PythonComponent(EXP_Value):

"""
Expand Down Expand Up @@ -1355,7 +1353,7 @@ show all of these property types.
"""

object: bge.types.KX_GameObject = ...
object: KX_GameObject = ...

"""
Expand Down Expand Up @@ -1438,7 +1436,7 @@ and can be optionally overridden as below:

...

class KX_Scene(bge.types.EXP_PyObjectPlus):
class KX_Scene(EXP_PyObjectPlus):

"""
Expand Down Expand Up @@ -1488,15 +1486,15 @@ what it does!
"""

objects: typing.Union[typing.Sequence[bge.KX_GameObject], typing.Mapping[str, bge.KX_GameObject], bge.types.EXP_ListValue] = ...
objects: typing.Union[typing.Sequence[KX_GameObject], typing.Mapping[str, KX_GameObject], bge.types.EXP_ListValue] = ...

"""
A list of objects in the scene, (read-only).
"""

objectsInactive: typing.Union[typing.Sequence[bge.KX_GameObject], typing.Mapping[str, bge.KX_GameObject], bge.types.EXP_ListValue] = ...
objectsInactive: typing.Union[typing.Sequence[KX_GameObject], typing.Mapping[str, KX_GameObject], bge.types.EXP_ListValue] = ...

"""
Expand Down Expand Up @@ -1528,7 +1526,7 @@ what it does!
"""

active_camera: bge.types.KX_Camera = ...
active_camera: KX_Camera = ...

"""
Expand All @@ -1547,23 +1545,23 @@ what it does!
"""

overrideCullingCamera: bge.types.KX_Camera = ...
overrideCullingCamera: KX_Camera = ...

"""
The override camera used for scene culling, if set to None the culling is proceeded with the camera used to render.
"""

world: bge.types.KX_WorldInfo = ...
world: KX_WorldInfo = ...

"""
The current active world, (read-only).
"""

filterManager: bge.types.KX_2DFilterManager = ...
filterManager: KX_2DFilterManager = ...

"""
Expand Down Expand Up @@ -1674,7 +1672,7 @@ The callbacks can take as argument the rendered camera, the camera could be temp

...

def addObject(self, object: typing.Union[bge.KX_GameObject, str], reference: typing.Union[bge.KX_GameObject, str], time: float = 0.0, dupli: bool = False) -> bge.types.KX_GameObject:
def addObject(self, object: typing.Union[KX_GameObject, str], reference: typing.Union[KX_GameObject, str], time: float = 0.0, dupli: bool = False) -> KX_GameObject:

"""
Expand Down
2 changes: 1 addition & 1 deletion tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def test_parse_module(rst_path: Path, settings: Values, app: Sphinx):
module = next(iter(types.parse(settings, app.env).traverse(Module)))
imports = module.imports

assert set(map(lambda i: i.module, imports)) == {"logging", "bpy", "typing", "mathutils", "bge"}
assert set(map(lambda i: i.module, imports)) == {"logging", "bpy", "typing", "mathutils"}

assert len(module.members) == 3
assert all(map(lambda c: classes[c.name] == c, module.traverse(Class)))
Expand Down

0 comments on commit 151c8b1

Please sign in to comment.