Skip to content

"Operator not supported" type error when using singleton constructs #1115

Description

@AaronAsAChimp

When using any of the singleton constructs (Bit, Int8ub, etc.) Pyright gives a false type error. This appears to be related #1018, but in this case its the type checker that thinks its a function when its actually been changed to variable.

The following struct:

BitParser = BitStruct(
    "is_bit" / Bit,
)

Gives this error:

Operator "/" not supported for types "Literal['is_bit']" and "() -> BitsInteger"

Potential solution

It might be simpler, especially for things like Bit, to just use a variable. For example,

@singleton
def Bit():
    """A 1-bit integer, must be enclosed in a Bitwise (eg. BitStruct)"""
    return BitsInteger(1)

is functionally identical to:

Bit = BitsInteger(1)
"""A 1-bit integer, must be enclosed in a Bitwise (eg. BitStruct)"""

This should cause fewer problems with type checking and make the code easier to read and maintain.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions