Select to view content in your preferred language

Better type hinting for arcpy.env

110
2
Tuesday
Status: Open
HaydenWelch
Occasional Contributor II

I pretty frequently find myself using tons of magic strings and flip flopping of environment variables in my scripts.

I have implemented something that does this as best as I can here  as an example solution. It's essentially a carbon copy of the EnvManager class but with explicitly defined environments so a static type checker can help you make sure you're feeding correct values and parameters to the GPEnvironment object.

This could also be implemented in a .pyi file for EnvManager.py to allow for forwards compatibility with changes to env parameters and type hinting updates could lag behind without causing issues.

HaydenWelch_0-1721764967861.png

 

2 Comments
JoshuaBixby

ArcPy already has a full-blown context manager for managing geoprocessing environments:  EnvManager—ArcGIS Pro | Documentation

HaydenWelch

@JoshuaBixby 

 

Well, I'm dumb. At least this is still useful for the type hinting and auto completion/literals lol.

 

Updated the title to reflect that.