Missing docstrings when pyi stub present

Answered

I'm not sure if this is an issue in PyCharm or somewhere in my setup, but I've recently been attempting to create pyi stub files for some libraries generated using sip.

If I don't use the pyi files (e.g. if I delete them) then PyCharm can display the docstrings for functions in this library using the Ctrl+Q shortcut without issue. e.g.

class QgsFeature 
def setGeometry(self, *args, **kwargs) Inferred type: (self: QgsFeature, args: Tuple[Any, ...], kwargs: Dict[str, Any]) -> None
Set the feature's geometry. The feature will be valid after.

geometry:
new feature geometry
See Also
geometry
See Also
clearGeometry    

 

But when the pyi files are present, while I get the nice type hinting support, I lose the docstrings in the quick help window, and instead just see:

class QgsFeature(wrapper)  def setGeometry(self, geometry: 'QgsGeometry') Inferred type: (self: QgsFeature, geometry: QgsGeometry) -> None 

If I inspect the pyi file, the method is included as:

class QgsFeature(sip.wrapper):
def setGeometry(self, geometry: 'QgsGeometry') -> None: ...

If I type help(QgsFeature.setGeometry) in the interactive Python console, I see the proper docstring. So I'm wondering if this is an issue in PyCharm, or whether there's a problem with the pyi files generated by sip. Is there anyway to get both the typehints using a .pyi stub while maintaining the full docstrings available when no stub is present? 

 

1
1 comment

Yes, docstrings from .pyi stubs should have precedence but if there are none we use those from actual definitions. Which version of PyCharm do you use?

0

Please sign in to leave a comment.