Skip to content

Segfault calling np.dtype on bad object due to recursion #12751

@jcrist

Description

@jcrist

This came up in Dask (dask/dask#4387). We have an object (dask.delayed.Delayed) that duck-types method/attribute access to build a graph from user code. Unfortunately this means that when np.dtype tries to get the dtype attribute it succeeds but doesn't return a valid dtype (it returns another delayed object). This leads to recursion and eventually a segfault.

I'm able to reproduce his without dask as follows:

import numpy as np

class ShouldHaveNoDtype(object):
    """This class happens to have a dtype attribute, but it doesn't actually
    meet the interface"""
    @property
    def dtype(self):
        """Has the attribute, but doesn't return a dtype, leading to recursion"""
        return self


x = ShouldHaveNoDtype()
np.dtype(x)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions