Skip to content

Keybinding comparing itself to str is really weird.  #108

@Carreau

Description

@Carreau
  • app-model version: 0.1.4
  • Python version: 3.10
  • Operating System: Mac

Description

I see what you are doing with Keybinding, and trying to make it magically work with strings, but I think it's a footgun in the long run.

What I Did

In [1]: from app_model.types import KeyBinding

In [2]: X = [KeyBinding.from_str('A')]

In [3]: [isinstance(s, str) for s in X]
Out[3]: [False]

In [4]: 'A' in X
Out[4]: True

For me Out[3] logically implies that In [4] Cannot be True. And equal but hash is different is a footgun as well:

In [7]: d = {}

In [8]: d[X[0]] = 1

In [9]: d['A'] # must be 1 as X[0] == 'A' ?

No KeyError.

I think this is make worse by the fact that __str__ return the keybinding in the string form as now code in napari liberally use the object directly in places where it's implicitely str()'d.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions