Skip to content

PT022 gives a false positive with GDAL code #26332

Description

@jontwo

Summary

This is a bit of a niche issue, sorry, but when testing a GDALDataset, you need to keep the dataset in scope to avoid segfaults. This means you have to construct a fixture like this to give you a vector layer for testing with.

    @pytest.fixture
    def lyr1(self, fields, srs_wgs84):
        """Return a polygon layer for testing."""
        ds = self.create_temp_vector(lyr_names=["lyr1"], fields=fields, srs=srs_wgs84)
        lyr = ds.GetLayer()
        yield lyr

Once the layer goes out of scope, the dataset (ds) can be closed. If you return lyr, the ds will close and be garbage collected and you will get a segfault when you try and use the layer.

Feel free to close this issue as a Won't Fix, but I thought it was worth raising just in case. We can always noqa that line to keep Ruff quiet.

Version

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixesRelated to suggested fixes for violations

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions