Skip to content

Conversation

@alexfikl
Copy link
Collaborator

Not quite sure why this was made a dataclass in #322, but none of the subclasses were updated to be dataclasses too? This made some things not get picked up properly (as far as I can tell), like the updated attribute type

class PyOpenCLFakeNumpyNamespace(LoopyBasedFakeNumpyNamespace):
    _array_context: PyOpenCLArrayContext

@alexfikl
Copy link
Collaborator Author

Hm, pyright seems unhappy about this because now the variable types don't match. Better to make everyone a dataclass instead? Not quite sure what's the right way to have different types for _array_context besides making it generic.

@inducer
Copy link
Owner

inducer commented Jul 27, 2025

This made some things not get picked up properly (as far as I can tell), like the updated attribute type

Could you explain? What didn't get picked up? By whom? To what end? And: I'm not sure I understand why it's a problem that some classes in an inheritance graph are data classes and others not. That seems fine, no?

@alexfikl
Copy link
Collaborator Author

alexfikl commented Jul 28, 2025

Could you explain? What didn't get picked up? By whom? To what end? And: I'm not sure I understand why it's a problem that some classes in an inheritance graph are data classes and others not. That seems fine, no?

Oops, sorry, I threw this out a bit quick and forgot to explain. For a simplified example

from typing import TYPE_CHECKING

import pyopencl as cl
from arraycontext import PyOpenCLArrayContext

ctx = cl.create_some_context()
queue = cl.CommandQueue(ctx)
actx = PyOpenCLArrayContext(queue)

assert actx.np._array_context.queue is queue

if TYPE_CHECKING:
    reveal_type(actx.np._array_context)

I first ran into this with pylint, which says

> python -m pylint --disable=all --enable=E --disable=E1136 --enable=I0021 actx.py
***** Module actx
actx.py:10:7: E1101: Instance of 'ArrayContext' has no 'queue' member (no-member)

but basedpyright also complains

> basedpyright actx.py
.../arraycontext/actx.py
.../arraycontext/actx.py:10:8 - warning: Type of "queue" is unknown (reportUnknownMemberType)
.../arraycontext/actx.py:10:31 - error: Cannot access attribute "queue" for class "ArrayContext"
Attribute "queue" is unknown (reportAttributeAccessIssue)
.../arraycontext/actx.py:13:17 - information: Type of "actx.np._array_context" is "ArrayContext"

My guess is that neither one picks up

class PyOpenCLFakeNumpyNamespace(LoopyBasedFakeNumpyNamespace):
    _array_context: PyOpenCLArrayContext

Are you seeing this too or is it just my setup?

I thought this was a dataclass issue, but it might also be because of the return types of _get_fake_numpy_namespace or something. I'll look more into it.

EDIT: Adding a np: PyOpenCLFakeNumpyNamespace to PyOpenCLArrayContext seems to appease the type checkers, but pylint is still unhappy..

@alexfikl alexfikl marked this pull request as draft July 28, 2025 13:55
@inducer
Copy link
Owner

inducer commented Jul 28, 2025

EDIT: Adding a np: PyOpenCLFakeNumpyNamespace to PyOpenCLArrayContext seems to appease the type checkers, but pylint is still unhappy..

This seems like the way to go IMO. I'm not worried about pylint not "getting" it; I've already dropped it from CI.

@alexfikl alexfikl closed this Sep 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants