Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAINT: Add missing dtype overloads for object- and ctypes-based inputs #19503

Merged
merged 4 commits into from Jul 17, 2021

Conversation

charris
Copy link
Member

@charris charris commented Jul 17, 2021

Backport of #19468.

closes #19467

This PR modifies a number of overloads in the np.dtype constructor, adding support for the various
ctypes._SimpleCData subclasses. Secondly, it adds a catchall overload for Type[object] which was
previously missing.

Examples

import ctypes
import numpy as np
from typing import TYPE_CHECKING

dtype_object = np.dtype(object)
dtype_c_long = np.dtype(ctypes.c_long)

if TYPE_CHECKING:
    reveal_type(dtype_object)  # Revealed type is "numpy.dtype[numpy.object_]"
    reveal_type(dtype_c_long)  # Revealed type is "numpy.dtype[numpy.signedinteger[numpy.typing._64Bit]]"

@charris charris added this to the 1.21.1 release milestone Jul 17, 2021
@charris charris changed the base branch from main to maintenance/1.21.x July 17, 2021 00:54
@charris charris closed this Jul 17, 2021
@charris charris reopened this Jul 17, 2021
@charris charris merged commit 7b27ba9 into numpy:maintenance/1.21.x Jul 17, 2021
@charris charris deleted the backport-19468 branch July 17, 2021 02:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect dtype-ctypes static typing
1 participant