PDAL / python

PDAL's Python Support
Other
116 stars 34 forks source link

fix: avoid mutable list as class attributable in `pdal.pio.PipelineSpec` #98

Closed spolloni closed 2 years ago

spolloni commented 2 years ago

The pdal.pio.PipelineSpec class defines the class atribute stages as an empty list:

https://github.com/PDAL/python/blob/3b534aff4cfafef8dc93425f377adc506c22c237/pdal/pio.py#L96

Because lists are mutable objects, this creates adverse consequences when defining multiple pipelines in the same runtime. An example:

>>> from pdal import pio

>>> a_pipeline = pio.readers.las(filename="file.laz")
>>> a_pipeline.pipeline # needed to instantiate PipelineSpec()
<pdal.pio.PipelineSpec object at 0x101e7fdc0>

>>> another_pipeline = pio.readers.las(filename="file.laz")
>>> another_pipeline.pipeline
<pdal.pio.PipelineSpec object at 0x101ed5940>

>>> yet_another_pipeline = pio.readers.las(filename="file.laz")
>>> len(yet_another_pipeline.pipeline.stages)
3

This PR fixes this by first defining stages as a instance attribute instead.

hobu commented 2 years ago

pio is now dead due to the refactor. please try the new API out and provide some feedback!