Skip to content

Better type checking for XBlock fields #710

Description

@kdmccormick

Given a class like this:

class MyBlock(XBlock):
    my_bool = xblock.fields.Boolean(...)

I want mypy to understand this:

type(MyBlock.my_bool)               # --> xblock.fields.Boolean
type(instance_of_my_block.my_bool)  # --> bool

We can kinda hack around it right now by doing this:

class MyBlock(XBlock):
    my_bool: bool = xblock.fields.Boolean(...)

but that annotation isn't entirely correct, because the class-level attribute will always be an instance of xblock.fields.Field.

We should see what django-stubs does in order to make this work for Django models, which are in a similar situation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateThis issue or pull request already exists elsewhere

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions