Skip to content

docs: add optype.numpy.ctypeslib reference page#581

Open
Aniketsy wants to merge 8 commits into
jorenham:masterfrom
Aniketsy:fix-448
Open

docs: add optype.numpy.ctypeslib reference page#581
Aniketsy wants to merge 8 commits into
jorenham:masterfrom
Aniketsy:fix-448

Conversation

@Aniketsy

Copy link
Copy Markdown
Contributor

fixes #448

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new reference page documenting the optype.numpy.ctypeslib module, which provides typed ctypes constructor reexports and abstract typing aliases for NumPy scalar-like C types (addressing the request in #448 to document this niche-but-existing API surface).

Changes:

  • Introduces docs/reference/numpy/ctypeslib.md describing the reexported ctypes constructors exposed by optype.numpy.ctypeslib.
  • Documents the module’s higher-level abstract typing aliases (CType, CScalar, Array, numeric families, etc.).

Comment thread docs/reference/numpy/ctypeslib.md Outdated
Comment thread docs/reference/numpy/ctypeslib.md Outdated
Comment thread docs/reference/numpy/ctypeslib.md Outdated
Comment thread docs/reference/numpy/ctypeslib.md Outdated
Comment thread docs/reference/numpy/ctypeslib.md Outdated
Aniketsy and others added 3 commits April 23, 2026 22:31
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@Aniketsy

Copy link
Copy Markdown
Contributor Author

@jorenham could you please re-review request from copilot, so that we can check if anything is missing. Thanks!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 4 comments.

Comment thread docs/reference/numpy/ctypeslib.md
Comment thread docs/reference/numpy/ctypeslib.md Outdated
Comment thread docs/reference/numpy/ctypeslib.md
Comment thread docs/reference/numpy/ctypeslib.md Outdated
Comment thread docs/reference/index.md Outdated

@jorenham jorenham left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The navigation link is missing (see zensical.toml)

Comment on lines +76 to +90
<tr>
<td align="left"><code>CType</code></td>
<td align="left"><code>ctypes._SimpleCData[T]</code></td>
<td align="left">Scalar-value ctypes base type.</td>
</tr>
<tr>
<td align="left"><code>CScalar</code></td>
<td align="left"><code>ctypes._CData</code></td>
<td align="left">Broad base for ctypes objects (scalar, array, pointer, structure, union, ...).</td>
</tr>
<tr>
<td align="left"><code>Array</code></td>
<td align="left"><code>ctypes.Array[CT]</code> (including nested arrays)</td>
<td align="left"><code>CT</code> is bound to <code>CType</code>.</td>
</tr>

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've introduce a ct alias above (line 12), but here you use the full ctypes. module.

Comment on lines +91 to +95
<tr>
<td align="left"><code>SignedInteger</code>, <code>UnsignedInteger</code></td>
<td align="left">signed and unsigned integer constructor groups</td>
<td align="left"></td>
</tr>

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's a "constructor group"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i used for SignedInteger and UnsignedInteger "when we call to construct something", but i feel i was wrong here , it should be actual union type directly from our code like Int8 | Int16 | Int32 | Int64 | Short | IntC | IntP | Long | LongLong.
i'll update ..

Comment thread docs/reference/numpy/ctypeslib.md Outdated
<td align="left"><code>CT</code> is bound to <code>CType</code>.</td>
</tr>
<tr>
<td align="left"><code>SignedInteger</code>, <code>UnsignedInteger</code></td>

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep to to one row per type alias, and explicitly describe the (union of) C types.

Comment thread docs/reference/numpy/ctypeslib.md Outdated
</tr>
<tr>
<td align="left"><code>Void</code></td>
<td align="left"><code>ctypes.Structure | ctypes.Union</code></td>

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<td align="left"><code>ctypes.Structure | ctypes.Union</code></td>
<td align="left"><code>ct.Structure | ct.Union</code></td>

Comment on lines +96 to +105
<tr>
<td align="left"><code>Integer</code>, <code>Floating</code>, <code>ComplexFloating</code></td>
<td align="left">numeric scalar families</td>
<td align="left">Modeled via <code>CScalar</code> for static typing.</td>
</tr>
<tr>
<td align="left"><code>Inexact</code>, <code>Number</code></td>
<td align="left">combined numeric families</td>
<td align="left"><code>Inexact = Floating | ComplexFloating</code>, <code>Number = Integer | Floating | ComplexFloating</code>.</td>
</tr>

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should also be split up and described in terms of their actual union types, as above

Comment thread docs/reference/numpy/ctypeslib.md Outdated
<tr>
<th align="left">alias</th>
<th align="left">covers</th>
<th align="left">notes</th>

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this "notes" column. The type definitions speak for itself, and I expect that every reader of this page will understand that union types cannot be instantiated at runtime.

Comment thread docs/reference/numpy/ctypeslib.md Outdated
import ctypes as ct
```

## Reexported `ctypes` constructors

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## Reexported `ctypes` constructors
## Concrete types

Comment on lines +30 to +53
<tr>
<td align="left"><code>Int8</code>, <code>UInt8</code>, <code>Int16</code>, <code>UInt16</code>, <code>Int32</code>, <code>UInt32</code>, <code>Int64</code>, <code>UInt64</code></td>
<td align="left"><code>c_int8</code>, <code>c_uint8</code>, <code>c_int16</code>, <code>c_uint16</code>, <code>c_int32</code>, <code>c_uint32</code>, <code>c_int64</code>, <code>c_uint64</code></td>
<td align="left">fixed-width integers</td>
<td align="left"></td>
</tr>
<tr>
<td align="left"><code>Byte</code>, <code>UByte</code>, <code>Short</code>, <code>UShort</code>, <code>IntC</code>, <code>UIntC</code>, <code>IntP</code>, <code>UIntP</code>, <code>Long</code>, <code>ULong</code>, <code>LongLong</code>, <code>ULongLong</code></td>
<td align="left"><code>c_byte</code>, <code>c_ubyte</code>, <code>c_short</code>, <code>c_ushort</code>, <code>c_int</code>, <code>c_uint</code>, <code>c_ssize_t</code>, <code>c_size_t</code>, <code>c_long</code>, <code>c_ulong</code>, <code>c_longlong</code>, <code>c_ulonglong</code></td>
<td align="left">platform-width integers</td>
<td align="left"><code>UIntP</code> uses <code>c_size_t</code> (<code>c_void_p</code> on NumPy &lt; 2, but almost always equivalent).</td>
</tr>
<tr>
<td align="left"><code>Float32</code>, <code>Float64</code>, <code>LongDouble</code></td>
<td align="left"><code>c_float</code>, <code>c_double</code>, <code>c_longdouble</code></td>
<td align="left">floating-point</td>
<td align="left"><code>LongDouble</code> is mainly useful as a type annotation target.</td>
</tr>
<tr>
<td align="left"><code>Complex64</code>, <code>Complex128</code>, <code>CLongDouble</code></td>
<td align="left"><code>c_float_complex</code>, <code>c_double_complex</code>, <code>c_longdouble_complex</code></td>
<td align="left">complex floating-point</td>
<td align="left">Available on Python 3.14+ on non-Windows only; otherwise these aliases are <code>Never</code>.</td>
</tr>

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One row per type would make this easier to read.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, this make sense .

@Aniketsy

Aniketsy commented May 6, 2026

Copy link
Copy Markdown
Contributor Author

thanks for the review, this needs lot improvement, i'll take some time for this and update (maybe on sunday)

@Aniketsy

Copy link
Copy Markdown
Contributor Author

hoping did not miss anything, i'll try to verify once again from my side, as i think this is going to create pain for you to review 🙏 .

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.

Document optype.numpy.ctypes

3 participants