ArcGIS Pro

Type hints have arrived in ArcGIS Pro 3.3

Type hinting for ArcPy has been a frequently requested feature for IDEs outside ArcGIS Pro such as Visual Studio Code and PyCharm. It is now available as of ArcGIS Pro 3.3.

Type hinting is a popular Python 3.5+ feature that makes code easier to write. Type hints indicate the types of variables, function parameters, and return values.

To get the benefits of this functionality in Visual Studio Code, you must have the Python extension installed. For both Visual Studio Code and PyCharm, you must set the IDE’s interpreter to a Python environment containing arcpy such as arcgispro-py3 or a clone.

 

ArcPy Data Access Module

The largest area where type hinting was added with this release is for the Data Access module known as arcpy.da in Python. Previously, da would not come up as a suggestion when typing arcpy. but now it does as well as all of arcpy.da‘s functions and classes presented with their arguments and doc strings.

arcpy.da now shows up in typehinting including all its classes and functions.

Geoprocessing Tools

In ArcGIS Pro 3.2 you could see type hints for function parameters when the function was typed in the form of arcpy.toolName_toolBox, but in ArcGIS Pro 3.3 type hints were added for using functions in the format arcpy.toolBox.toolNamefor most tools.

arcpy.Buffer.Analysis() will display the documentation help on how you can fill in your parameters.

Functions with string literals

Some functions in arcpy have a defined list of strings for the parameter, called string literals. These string literals will now be displayed through type hinting as options you can choose from. This will save you time from having to refer back to the documentation to find the exact case you needed. For example, arcpy.ListDatasets has a parameter called feature_type that has a set list of strings to represent the feature type of the data you want to list with the function.

arcpy.ListDatasets has the feature_type parameter that will display the string literals you can choose from.

ArcPy Dictionary Objects

Similar to string literals, some arcpy dictionary objects will now display the list of dictionary keys for you when you type the left square bracket. You will no longer have to refer to the documentation or guess at which keys are available on objects such as arcpy.GetInstallInfo().

arcpy.GetInstallInfo() now displays the dictionary keys you can choose from.

Geoprocessing Result Objects

Running most geoprocessing tools with Python will return a Result object. Previously, you would need to refer to the documentation to find the particular properties and methods on the result object, but now with type hints, you can see them as you type your code.

Result objects now display properties and methods with typehints.

Some geoprocessing tools return another type of object such as a raster instead of the Result object. These do not yet have type hints enabled.

Summary

All of these type hints and more were added to ArcPy API at ArcGIS Pro 3.3 and can help you improve your code. You can write code to use a tool and fill out its parameters without having to refer back to the documentation.

The effort started at 3.3 was limited but will expand to more of the ArcPy API over the next few releases.

About the author

Kimberly Saballett

Kimberly is currently a product engineer on the Python team where she focuses on the design, evaluation, and documentation of new and existing Python functionality. She began her career at Esri in 2018 working in Technical Support.

Subscribe
Notify of
1 Comment
Oldest
Newest
Inline Feedbacks
View all comments

Next Article

Maxar's Precision3D in Esri's World Elevation 3D and Hillshade Layers

Read this article