beeware / beeware/toga

Confusion around style properties which accept NONE values

Open
#1,502 3 comments 0 reactions 0 assignees View on GitHub
bug documentation
Dominant language
Python
Stars
5.4k
Forks
827
Avg merge
9h 45m
Merged PRs (30d)
58

Description

Reported on Discord by "willow <3", and verified by me.

The [Pack documentation](https://toga.readthedocs.io/en/latest/reference/style/pack.html) says that `none` is allowed as the value of several properties. However, I can't find any tests for this, and it doesn't actually work.

For example, if you call `Pack(visibility="none")`, you get this error:

```
Traceback (most recent call last):
File "c:\users\smith\cygwin\.venv\bw-dev\lib\site-packages\travertino\declaration.py", line 178, in setter
value = choices.validate(value)
File "c:\users\smith\cygwin\.venv\bw-dev\lib\site-packages\travertino\declaration.py", line 57, in validate
raise ValueError("'{0}' is not a valid initial value".format(value))
ValueError: 'None' is not a valid initial value

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "c:\users\smith\cygwin\git\beeware\toga\src\winforms\toga_winforms\app.py", line 216, in run_app
self.create()
File "c:\users\smith\cygwin\git\beeware\toga\src\winforms\toga_winforms\app.py", line 113, in create
self.interface.startup()
File "C:\Users\smith\cygwin\git\beeware\beeware-chaquopy-test\src\helloworld\app.py", line 21, in startup
style=Pack(visibility="none")),
File "c:\users\smith\cygwin\.venv\bw-dev\lib\site-packages\travertino\declaration.py", line 73, in __init__
self.update(**style)
File "c:\users\smith\cygwin\.venv\bw-dev\lib\site-packages\travertino\declaration.py", line 97, in update
setattr(self, name, value)
File "c:\users\smith\cygwin\.venv\bw-dev\lib\site-packages\travertino\declaration.py", line 180, in setter
raise ValueError("Invalid value '{}' for property '{}'; Valid values are: {}".format(
ValueError: Invalid value 'none' for property 'visibility'; Valid values are: hidden, none, visible
```

Passing a Python `None` gives the same error message, except for the capitalization of `'none'`.

It looks like the problem is that the string "none" is being converted to a Python `None`, and then compared to the available choices, one of which is the string "none".

However, in the case of `visibility`, for consistency with CSS, instead of `none` it would be better to use `hidden`, which is already implemented and tested, but not documented.

**Environment:**
- Operating System: Windows 10
- Python version: 3.8.7
- Software versions:
- Briefcase: 0.3.7 main branch
- Toga: 0.3.0.dev35 main branch

Contributor guide

Open the contributing guide

Research direction

Start with the Pack style-property definitions and the Pack documentation page at reference/style/pack.html, then inspect the validation path shown in travertino/declaration.py. Check the documented properties that accept none, including visibility, against existing tests and behavior. Done means the intended values are consistently accepted and documented, with visibility clarified in line with the issue's hidden suggestion.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
desktop
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.