Select to view content in your preferred language

Add typing stubs to mp module

222
1
07-22-2024 09:14 AM
Status: In Product Plan
Labels (1)
HaydenWelch
Frequent Contributor

Currently the only type that has an interface in the mp module is `ArcGISProject`. This causes tons of headaches when working with any other mapping classes as Pylance has no idea what any of the types in the module are. This has already been done for a lot of da module objects (*Cursor, Editor, etc.), but for some reason the mp module is still reliant on the developer reading the documentation online for each type instead of allowing for Pylance to provide documentation inline.

Proposed fix:

`_mp.py` ->

 

 

...
__all__ = ["ArcGISProject", "Bookmark", "BookmarkMapSeries", "Camera", 
           "ElevationSurface", "ElevationSource", "GraphicElement", 
           "GroupElement", "LabelClass", "Layer", "LayerFile", "LayerTime", "Layout", 
           "LegendElement", "LegendItem", "Map", "MapFrame", "MapSeries", "MapSurroundElement", 
           "MapTime", "MapView", "PictureElement", "Report", "ReportLayoutSection", 
           "ReportSection", "StyleItem", "Table", "TableFrameElement", "TextElement"]
...

 

 

`mp.py` ->

 

 

...
from arcpy._mp import *
...

 

 

Alternatively the method used by the da module could be used by mp as well:

 

 

...
__all__ = [item for item in dir(da) if not item.startswith('_')]

locals().update(da.__dict__)
del da
...

 

 

With da being replaced by mp of course.

 

Final option is to create a `stubs/mp.pyi` that explicitly types all classes and methods for the mp module. See da.pyi in the arcpy module root for an example. This would probably be the best option as it wouldn't require modifying anything in the mp module itself (other than making sure all interfaced classes are in the mp.py namespace using some import method)

 

1 Comment
JeffBarrette
Status changed to: In Product Plan

Thank you for your feedback.  We hope to incorporate type hints into many more of our classes for the 3.5 release.

Jeff - arcpy.mp and Layout teams