Python type annotation stubs included in aspose-cells-python package are broken

I am so happy to see that aspose-cells-python includes type annotations in the form of stub (.pyi) files. Thank you for taking the time to include them. When they work, they improve the use of a python package by providing valuable feedback and enabling hinting in IDEs.

That said, the stubs included with aspose-cells-python are currently broken, including syntax errors, undefined names, etc. And mypy won’t even consider them because the package is missing the required py.typed file at the package root. And PyCharm provides incomplete type hints because it cannot completely parse the stubs due to the syntax errors. If I add a py.typed file to the root of the installed package, mypy will then find the stubs but is only able to report the first syntax error it encounters.

Stub files can be checked using mypy. If mypy cannot verify a package’s stub files, then it will not be able to verify the type annotations where they are used in code. I would recommend adding a unit test to check the stub files before shipping.

$ mypy --strict -m aspose.cells
aspose/cells/drawing/equations/__init__.pyi:3327: error: unterminated string literal (detected at line 3327)  [syntax]
Found 1 error in 1 file (errors prevented further checking)

I went through the top-level stub for aspose-cells-python and produced a working version that might help you see the difference. In fact, I would recommend diffing it against the shipped version.

stubs.zip (93.0 KB)

I don’t think it would take a lot of work to fix the stubs, and it would be a huge help to those using the package. IDEs would be able to provide better type hinting, and mypy would catch type issues.

Would you please consider fixing the stubs and adding a py.typed file?

Thank you.

(Tested with python 3.10 and aspose-cells-python 24.9.0)

@brandon.avantus
Thank you very much for your discovery. We will evaluate this issue, and we have created a ticket ID( CELLSPYTHONNET-221) in our internal system to track it. We will notify you once there are updates! Thank you!

The issues you have found earlier (filed as CELLSPYTHONNET-221) have been fixed in this update. This message was posted using Bugs notification tool.

Wow! What a quick response. Thank you.

I upgrade to aspose-cells-python 24.10.0 this morning and ran mypy 1.11.2 against it, and it is a huge improvement. There are still some undefined names. Maybe that can be fixed in the next release? It’s mostly around .NET classes that don’t seem to have a clear mapping in aspose. They can be fixed by just adding an annotation making them of type Any:

System: Any
Guid: Any

Here are the errors I’m now seeing from mypy:

$ mypy --strict -p aspose.cells
.venv/lib/python3.10/site-packages/aspose/cells/revisions/__init__.pyi:318: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/rendering/__init__.pyi:295: error: Name "aspose.pydrawing.imaging.ImageFormat" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/rendering/__init__.pyi:301: error: Name "aspose.pydrawing.imaging.ImageFormat" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/rendering/__init__.pyi:339: error: Name "aspose.pydrawing.text.TextRenderingHint" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/rendering/__init__.pyi:345: error: Name "aspose.pydrawing.text.TextRenderingHint" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/rendering/__init__.pyi:351: error: Name "aspose.pydrawing.drawing2d.SmoothingMode" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/rendering/__init__.pyi:357: error: Name "aspose.pydrawing.drawing2d.SmoothingMode" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/rendering/__init__.pyi:373: error: Name "aspose.pydrawing.imaging.PixelFormat" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/rendering/__init__.pyi:378: error: Name "aspose.pydrawing.imaging.PixelFormat" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/rendering/__init__.pyi:503: error: Name "aspose.pydrawing.imaging.EmfType" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/rendering/__init__.pyi:508: error: Name "aspose.pydrawing.imaging.EmfType" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/rendering/__init__.pyi:877: error: Name "aspose.pydrawing.printing.PrinterSettings" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/rendering/__init__.pyi:884: error: Name "aspose.pydrawing.printing.PrinterSettings" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/rendering/__init__.pyi:907: error: Name "aspose.pydrawing.printing.PrintPageEventArgs" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/rendering/__init__.pyi:1000: error: Name "aspose.pydrawing.printing.PrinterSettings" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/rendering/__init__.pyi:1007: error: Name "aspose.pydrawing.printing.PrinterSettings" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/rendering/__init__.pyi:1030: error: Name "aspose.pydrawing.printing.PrintPageEventArgs" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/properties/__init__.pyi:599: error: Overloaded function signature 4 will never be matched: signature 2's parameter type(s) are the same or broader  [misc]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:1043: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:1048: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:2234: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:2239: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:3258: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:3263: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:4283: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:4288: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:5312: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:5317: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:6449: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:6454: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:7515: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:7520: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:8558: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:8563: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:9582: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:9587: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:11073: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:11078: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:12119: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:12124: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:13147: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:13152: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:14689: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:14694: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:15789: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:15794: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:17415: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:17420: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:18664: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:18669: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:19843: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:19848: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:21121: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:21126: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:22170: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:22175: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:23278: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:23283: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:24448: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:24453: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:25324: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:25329: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:25334: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:25339: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:26420: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:26425: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:27478: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:27483: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:28580: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:28585: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:30109: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/drawing/__init__.pyi:30114: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/digitalsignatures/__init__.pyi:41: error: Name "System" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/digitalsignatures/__init__.pyi:46: error: Name "System" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/digitalsignatures/__init__.pyi:71: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/digitalsignatures/__init__.pyi:77: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/digitalsignatures/__init__.pyi:107: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/digitalsignatures/__init__.pyi:113: error: Name "Guid" is not defined  [name-defined]
.venv/lib/python3.10/site-packages/aspose/cells/charts/__init__.pyi:1020: error: Name "aspose.pydrawing.Size" is not defined  [name-defined]
Found 79 errors in 6 files (checked 29 source files)

Thanks again for the quick fix. The errors above are minor. That the syntax errors are all gone is huge.

I just noticed that a py.typed file was added to every directory. It only needs to exist in the root aspose directory to indicate that the entire package is type annotated.

@brandon.avantus,

Thank you for your feedback and for highlighting those minor issues and other findings. We will evaluate them and address them accordingly soon.

@brandon.avantus
Hi, thank you for your feedback. We were able to reproduce the issue you mentioned after running mypy --strict -p aspose.cells. Previously, we only used mypy --strict -m aspose.cells, and it did not show any errors. We will continue working on the issue you raised and have reopened ticket ID (CELLSPYTHONNET-221). We will notify you here once there is an update.