sizmailov / pybind11-stubgen

Generate stubs for python modules
Other
233 stars 47 forks source link

Add optional annotation quation #59

Closed daltairwalter closed 2 years ago

daltairwalter commented 3 years ago

I am renaming the output files to be module.py in an attempt to use pylint. This mostly works, but I see some errors when there are forward declarations.

pyi def registerUserDefinedAlgorithm(self, arg0: UserDefinedRegistrationInformation) -> None: ...

The error goes away if I add quotes like this: def registerUserDefinedAlgorithm(self, arg0: 'UserDefinedRegistrationInformation') -> None: ...

pylint error [E0601(used-before-assignment)Factory.registerUserDefinedAlgorithm] Using variable 'UserDefinedRegistrationInformation' before assignment

daltairwalter commented 3 years ago

The future annotations feature seems to work for this too. This seems better then the quote option.

from future import annotations

daltairwalter commented 3 years ago

apparently I missed a code identifier

from __future__ import annotations

sizmailov commented 3 years ago

Note that pybind11-stubgen does not perform analysis of the modules, it's rather simple tool.

Although pybind11-stubgen does it's best to avoid such problems by reordering generated stubs, but it can fail if reordering won't help. I think optional quotation might be right solution to the problem:

Option 1. Quote everything triggered by --annotations-as-strings Option 2. Quote only listed items, e.g. --annotate-as-string=UserDefinedRegistrationInformation

sizmailov commented 2 years ago

Closed by f9dd91836e5acc37a4eb272c3c173ed3287eecc9