Skip to content

Pitfall with prevent_dispatch arg in Section class #2499

@ghost

Description

While developing using 3.0dev, I misread the documentation and passed in prevent_dispatch=False to allow events to pass to multiple sections. Because of my mistake, I spent 30 minutes trying to figure out why I'm not seeing any events in my other section.

This init code:

self.prevent_dispatch: Iterable = prevent_dispatch or {True}

Means that if the caller passes in False, it silently gets translates to {true}, which is not intuitive.

I realize this is documented and also that mypy would have caught it, but I fell for it so others probably would too. Since 3.0 is still in beta there's still the possibility of changing the API so I thought I might as well raise this point.

To me, It also seems natural for ''True|False" values to do what you'd expect, but I understand typing simplicity makes this less attractive.

Possible solutions:

  1. Use {True} if prevent_dispatch is None else prevent_dispatch instead
  2. Add asserts on input types.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions