Esri / arcgis-python-api

Documentation and samples for ArcGIS API for Python
https://developers.arcgis.com/python/
Apache License 2.0
1.83k stars 1.09k forks source link

Layer.fromitem expects an Item object when the documentation and example are for a string #1554

Closed phaakma closed 1 year ago

phaakma commented 1 year ago

Describe the bug The arcgis.gis.Layer class has a method called fromitem. The documentation is unclear. In the documentation online the example says it returns a layer from an Item object, but then for the input parameters says to pass in the id of an item as a string. The example given in the documentation also shows passing in the item id as a string. But doing this throws an error saying: 'str' object has no attribute 'layers'

This is because the method requires an Item object. Passing in an Item object works.

To Reproduce Steps to reproduce the behavior:

lyr = Layer.fromitem("fa0a755689b54bc2aab262ea57dce694", index=0)
lyr

error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [15], in <cell line: 1>()
----> 1 lyr = Layer.fromitem("fa0a755689b54bc2aab262ea57dce694", index=0)
      2 lyr

File /opt/conda/lib/python3.9/site-packages/arcgis/gis/__init__.py:15545, in Layer.fromitem(cls, item, index)
  15523 @classmethod
  15524 def fromitem(cls, item: str, index: int = 0):
  15525     """
  15526     The ``fromitem`` method returns the layer at the specified index from a layer :class:`~arcgis.gis.Item` object.
  15527 
   (...)
  15543         >>> layer.fromitem(item="9311d21a9a2047d19c0faaebd6f2cca6", index=3)
  15544     """
> 15545     return item.layers[index]

AttributeError: 'str' object has no attribute 'layers'

Screenshots If applicable, add screenshots to help explain your problem. image

Expected behavior Passing in either an item id as a string or an Item object should return the layer.

Platform (please complete the following information):

Additional context Add any other context about the problem here, attachments etc.

achapkowski commented 1 year ago

Layer is a base class, and really shouldn't be used. What are you trying to do?

phaakma commented 1 year ago

Hi. Thanks for reply - this report is simply pointing out that the documentation differs from implementation, and pointing out what is expected based on the docs.

nanaeaubry commented 1 year ago

This will be fixed for the next release, thanks for pointing it out