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

Add type hints and check them in CI #707

Open
kdmccormick opened this issue Jan 12, 2024 · 7 comments
Open

Add type hints and check them in CI #707

kdmccormick opened this issue Jan 12, 2024 · 7 comments
Assignees

Comments

@kdmccormick
Copy link
Member

kdmccormick commented Jan 12, 2024

XBlock is a widely used core library, but is pretty abstract and thus can be hard to reason about. So, this would be a particularly valuable repo to add type hinting to.

Some additional notes are here:

Draft PR here:

kdmccormick added a commit that referenced this issue Jan 12, 2024
Adds opaque-keys as a dependency for some new unit tests.
Normally I wouldn't add a dependency just for a couple tests,
but we anticipate to make the repo depend on opaque-keys soon
anyway:

* #707
* #708

Bumps version from 1.9.1 to 1.10.0
kdmccormick added a commit that referenced this issue Jan 12, 2024
Adds opaque-keys as a dependency for some new unit tests.
Normally I wouldn't add a dependency just for a couple tests,
but we anticipate to make the repo depend on opaque-keys soon
anyway:

* #707
* #708

Bumps version from 1.9.1 to 1.10.0
kdmccormick added a commit that referenced this issue Jan 23, 2024
Add two new properties to `XBlock` objects: `.usage_key` and
`.context_key``. These simply expose the values of
`.scope_ids.usage_id`` and `.scope_ids.usage_id.context_key`,
providing a convenient replacement to the deprecated,
edx-platform-specific block properties `.location` and `.course_id`,
respectively.

Note: this adds opaque-keys as a dependency for some new unit tests.
Normally I wouldn't add a dependency just for a couple tests,
but we anticipate to make the repo depend on opaque-keys soon
anyway:

* #707
* #708

Bumps version from 1.9.1 to 1.10.0
kdmccormick added a commit that referenced this issue Jan 24, 2024
Add two new properties to `XBlock` objects: `.usage_key` and
`.context_key`. These simply expose the values of
`.scope_ids.usage_id`` and `.scope_ids.usage_id.context_key`,
providing a convenient replacement to the deprecated,
edx-platform-specific block properties `.location` and `.course_id`,
respectively.

Note: this adds opaque-keys as a dependency for some new unit tests.
Normally it wouldn't make sense to add a dependency just for a couple
of tests, but we anticipate to make the repo depend on opaque-keys:
soon anyway, for:

* #707, and
* #708

Bumps version from 1.9.1 to 1.10.0
@kdmccormick kdmccormick self-assigned this Jan 30, 2024
@kdmccormick
Copy link
Member Author

early WIP: #713

@kdmccormick
Copy link
Member Author

kdmccormick commented Jan 31, 2024

@bradenmacdonald I've been working on this, and it's going pretty well. I'm actually really impressed how far mypy has come--typing XBlock Fields as generic descriptors works great!

The hardest part so far has been dealing with how XBlock's implementation is chopped up into a bunch of tiny mixins. I guess that was in anticipation of supporting a bunch of XBlock-like classes that don't use all of XBlock's capability, but AFAICT we only have XBlock and XBlockAside. A good demonstration of the pain is HierarchyMixin, which is written in such a way that I can't see it ever working outside of the XBlock class. Here's the typing hack I'm using to get around it.

I'm really tempted to collapse nearly all the mixins down into a simple hierarchy:

class Plugin:
    ... # as is
class ScopedStorageMixin:
    ... # collapse in: RuntimeServicesMixin
        # could be better named: RuntimeAndStorageMixin

class XBlockMixin(ScopedStorageMixin):
    ... # as is

class SharedBlockBase(ScopedStorageMixin, Plugin):
    ... # collapse in: XmlSerializationMixin, HandlersMixin

class XBlockAside(SharedBlockBase):
    ... # as is

class XBlock(SharedBlockBase):
    ... # collapse in: HierarchyMixin, ViewsMixin

Does that sound like a good move? Or do you think the current set of mixins is worth keeping around?

@kdmccormick
Copy link
Member Author

kdmccormick commented Jan 31, 2024

Alternatively, here's an even more aggressive simplification. It would add capability to XBlockMixin, but I honestly think we'll need that extra capability when we go to apply type-checking to the XBlockMixins in edx-platform:

class Plugin:
   ... # as-is
class Blocklike:
   ... # collapse in: RuntimerServicesMixin, ScopedStorageMixin, XmlSerializationMixin, HandlersMixin

class XBlockMixin(Blocklike):
   ... # as is

class XBlockAside(Blocklike, Plugin):
   ... # as is

class XBlock(Blocklike, Plugin):
   ... # collapse in: HierarchyMixin, ViewMixin

@bradenmacdonald
Copy link
Contributor

@kdmccormick I think that the only useful aspect of the current mixins is code organization - grouping similar functions, attributes, etc. together in their own files. I don't think they're actually used separately in any meaningful way. So I'm totally in favor of some simplifications.

In fact, the current organization often makes it hard for me to find code when I need to look something up, if I can't remember which mixin it's in.

@ashultz0
Copy link

Having been in those mixins in specific trying to understand how xblock asides work, I could not be more in favor of collapsing them together.

And In general the code uses way too many mixins so if there's an opportunity to lower that with no side effects that's awesome.

@kdmccormick
Copy link
Member Author

Great! I opened:

I will probably open a separate PR for the mixin collapsing, which I'll rebase #713 onto.

@kdmccormick
Copy link
Member Author

This is almost ready or review: #761

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 a pull request may close this issue.

3 participants