Select to view content in your preferred language

Better type hinting for arcpy.env

265
3
07-23-2024 01:04 PM
Status: In Product Plan
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

 

3 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.

HannesZiegler
Status changed to: In Product Plan

We're working on this!  This status does not guarantee that the functionality will be in the next release, but development work has begun. Release cycles vary by product so make sure to check the product life cycle information to get an idea of when to expect the next release.