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

Label init with max_glyphs instead of text value is broken #141

Closed
flavio-fernandes opened this issue Mar 13, 2021 · 0 comments · Fixed by #142
Closed

Label init with max_glyphs instead of text value is broken #141

flavio-fernandes opened this issue Mar 13, 2021 · 0 comments · Fixed by #142

Comments

@flavio-fernandes
Copy link
Contributor

When Label class is initialized with size instead of text.
The split function is attempted in None object instead of an empty string.
That will cause this:

      File "/lib/adafruit_display_text/label.py", line 84, in __init__
      AttributeError: 'NoneType' object has no attribute 'split'

This is code with this issue (look at lines 78 ans 84):

text = kwargs.get("text", None)
if not max_glyphs and not text:
raise RuntimeError("Please provide a max size, or initial text")
self._tab_replacement = kwargs.get("tab_replacement", (4, " "))
self._tab_text = self._tab_replacement[1] * self._tab_replacement[0]
text = self._tab_text.join(text.split("\t"))

To reproduce, simply create a Label like this:

import terminalio
from adafruit_display_text import label

text_area = label.Label(terminalio.FONT, max_glyphs=10)

This used to work, so I suspect it is a regression introduced here:
2b4f1ad

flavio-fernandes added a commit to flavio-fernandes/Adafruit_CircuitPython_Display_Text that referenced this issue Mar 13, 2021
This change addresses cases when Label class is initialized with
max_glyphs instead of text. In such cases, the split function is
attempted on None object instead of an empty string:

  File "/lib/adafruit_display_text/label.py", line 84, in __init__
  AttributeError: 'NoneType' object has no attribute 'split'

Fixes: adafruit#141
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant