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

How to type records #126

Open
shaunc opened this issue Dec 26, 2024 · 1 comment
Open

How to type records #126

shaunc opened this issue Dec 26, 2024 · 1 comment

Comments

@shaunc
Copy link

shaunc commented Dec 26, 2024

I have a recarray, typed as:

NodeType = Structure[
    """
    value: Float32,
    weight: Float32,
    left: UInt16,
    right: UInt16,
    parent: UInt16,
    balance: Int8,
    """
]
NodeArrayType = RecArray[Shape["*"], NodeType]

Using individual node "works" because getitem returns Any (shouldn't it return NodeType?):

node = nodes[i_node]  # node type: Any
node.left = ... # ok

But when I pass a node to a subroutine, shouldn't its type be "NodeType"?

def foo(node: NodeType) -> None:
    node.left = ... # pylance type error 
    # "Cannot assign to attribute "value" for class "NodeType" Attribute "value" is unknown"

Is this a pylance (pyright) specific problem ... or am I using NodeType wrongly for individual records?

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

No branches or pull requests

2 participants
@shaunc and others