FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix selector example code · Issue #68 · frequenz-floss/frequenz-dispatch-python · GitHub

Repository navigation

Fix selector example code #68

Closed
Closed

Description

What happened?

This code is used in some examples:

            match components:
                case [int(), *_] as component_ids:
                    print("Dispatch: Setting components to %s", components)
                case [ComponentCategory.BATTERY, *_]:
                    print("Dispatch: Using all battery components")
                case unsupported:
                    print(
                        "Dispatch: Requested an unsupported selector %r, "
                        "but only component IDs or category BATTERY are supported.",
                        unsupported,
                    )

But it doesn't work when trying to assign component_ids to a variable hinted with type list[int], mypy gives this error:

Incompatible types in assignment (expression has type "list[int] | list[ComponentCategory]", variable has type "list[int] | None") [assignment]

What did you expect instead?

Code examples to be robust and work for most use cases.

Affected part(s)

Documentation (part:docs)

Extra information

This code works:

match dispatch.selector:
            case []:
                print("Dispatch: Using all components")
            case list() as ids if isinstance(ids[0], int):
                component_ids = ids
            case [ComponentCategory.BATTERY, *_]:
                component_category = ComponentCategorySDK.BATTERY
            case unsupported:
                print(
                    "Dispatch: Requested an unsupported selector %r, "
                    "but only component IDs or category BATTERY are supported.",
                    unsupported,
                )

But ideally we should probably add some way to do these checks more easily for the users.

Activity

  1. added
    priority:❓We need to figure out how soon this should be addressed
    type:bugSomething isn't working
    on Oct 16, 2024
  2. added this to the v1.0.0 milestone on Dec 6, 2024
  3. added 2 commits that reference this issue on Jan 20, 2025
    f206dd2
    cc6e85e
  4. modified the milestones: v1.0.0, v0.6.0 on Sep 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    part:docsAffects the documentationpriority:❓We need to figure out how soon this should be addressedtype:bugSomething isn't working

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL