Skip to content

[TYP] Change typing for texts to StrLike #26867

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

oscargus
Copy link
Member

@oscargus oscargus commented Sep 22, 2023

PR summary

Related to #26858.

It is a bit unintuitive (maybe) to change like this, but apparently people are relying on set_text making the str-conversion.

Setting as draft for now as we probably should discuss it (and I have most likely missed some).

Additional classes/methods to change:

  • Annotation/annotate
  • TextArea
  • Figure.text
  • QuiverKey (label)
  • set_title etc.

PR checklist

@timhoffm
Copy link
Member

timhoffm commented Sep 22, 2023

One can see this as similar to %s or f-strings, where the parameter is implicitly converted to str. OTOH I'm reluctant to officially broaden the type to Any. This would be very general, and IHMO would loose the semantic aspect of the type definition.
The automatic str conversion decision may be intentional and for convenience. Due to compatibility, we're bound to the behavior whether we want or not. But I'm inclined to regard this rather as a gone-public implementation detail that we have to support, and not as an intended feature that we want to advertise.

Therefore, at least for the docstrings, I'm very much in favor of keeping str. It may be a technical solution to make a type alias StrLike = Any for annotations in this case, including a description why we use that. That'd be a somewhat simpler solution than the propsed SupportsStr protocol. It would placate the type system for current code, but still carry the semantics.

@oscargus oscargus changed the title [TYP] Change typing for texts to Any/object [TYP] Change typing for texts to StrLike Dec 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants