Skip to content

pyasn1: mypy error with doc example of SequenceOf #15369

@ggirol-rc

Description

@ggirol-rc

The docstring of SequenceOf in https://github.com/pyasn1/pyasn1/blob/2d2d8cfcf9bf2e9e7119efced7d57939a63b9605/pyasn1/type/univ.py#L1659C1-L1668C44 reads as follows:

from pyasn1.type.univ import SequenceOf, SetOf, Integer
class LotteryDraw(SequenceOf):  #  SetOf is similar
    '''
    ASN.1 specification:

    LotteryDraw ::= SEQUENCE OF INTEGER
    '''
    componentType = Integer()

lotteryDraw = LotteryDraw()
lotteryDraw.extend([123, 456, 789])

and with pyasn1==0.6.2 types-pyasn1==0.6.0.20250914 and mypy 1.19.1 (compiled: yes) I get this error:

test.py:8: error: Incompatible types in assignment (expression has type "Integer", base class "SequenceOfAndSetOfBase" defined the type as "Optional[NamedTypes]")  [assignment]
Found 1 error in 1 file (checked 1 source file)

Same applies with SetOf, by the way.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions