Repository: napari/napari

Issue:
Napari progress throws AttributeError if a description is set and it is disabled
## 🐛 Bug

`napari.utils.progress` throws an `AttributeError` if a description is set and it is disabled. This works in `tqdm`.

## To Reproduce

To reproduce it:
```python
# from tqdm import tqdm
from napari.utils import progress as tqdm

for z in tqdm(range(10), total=10, desc="Count to 10", disable=True):
    pass
```
This fails with:
```
Traceback (most recent call last):
  File "/home/pape/Work/playground/napari-prog/progress_napari.py", line 6, in <module>
    for z in tqdm(range(10), total=10, desc="Count to 10 again", disable=True):
  File "/home/pape/software/conda/miniconda3/envs/sam/lib/python3.10/site-packages/napari/utils/progress.py", line 88, in __init__
    if not self.desc:
AttributeError: 'progress' object has no attribute 'desc'
```
It works when using normal `tqdm`.

## Expected behavior

The code should not throw the exception.

## Environment

The napari and tqdm versions are (omitting the rest because irrelevant):
- napari                    0.4.17          pyh275ddea_0_pyqt    conda-forge
- tqdm                      4.65.0             pyhd8ed1ab_1    conda-forge

## Additional context

This should be easy to fix [here](https://github.com/napari/napari/blob/main/napari/utils/progress.py#L88).
For example, one could add the lines
```python
if self.disable:
  self.desc = ""
```
beforehand. I checked that locally and it fixes the issue.

I am happy to open a PR for this.
Napari progress throws AttributeError if a description is set and it is disabled
## 🐛 Bug

`napari.utils.progress` throws an `AttributeError` if a description is set and it is disabled. This works in `tqdm`.

## To Reproduce

To reproduce it:
```python
# from tqdm import tqdm
from napari.utils import progress as tqdm

for z in tqdm(range(10), total=10, desc="Count to 10", disable=True):
    pass
```
This fails with:
```
Traceback (most recent call last):
  File "/home/pape/Work/playground/napari-prog/progress_napari.py", line 6, in <module>
    for z in tqdm(range(10), total=10, desc="Count to 10 again", disable=True):
  File "/home/pape/software/conda/miniconda3/envs/sam/lib/python3.10/site-packages/napari/utils/progress.py", line 88, in __init__
    if not self.desc:
AttributeError: 'progress' object has no attribute 'desc'
```
It works when using normal `tqdm`.

## Expected behavior

The code should not throw the exception.

## Environment

The napari and tqdm versions are (omitting the rest because irrelevant):
- napari                    0.4.17          pyh275ddea_0_pyqt    conda-forge
- tqdm                      4.65.0             pyhd8ed1ab_1    conda-forge

## Additional context

This should be easy to fix [here](https://github.com/napari/napari/blob/main/napari/utils/progress.py#L88).
For example, one could add the lines
```python
if self.disable:
  self.desc = ""
```
beforehand. I checked that locally and it fixes the issue.

I am happy to open a PR for this.


Discussion:
@constantinpape thanks for raising! I think your identified fix is correct, so please feel free to open the PR :blush: 
@constantinpape thanks for raising! I think your identified fix is correct, so please feel free to open the PR :blush: 

Resolving patch:
diff --git a/napari/utils/progress.py b/napari/utils/progress.py
--- a/napari/utils/progress.py
+++ b/napari/utils/progress.py
@@ -85,6 +85,10 @@ def __init__(
         self.is_init = True
         super().__init__(iterable, desc, total, *args, **kwargs)
 
+        # if the progress bar is set to disable the 'desc' member is not set by the
+        # tqdm super constructor, so we set it to a dummy value to avoid errors thrown below
+        if self.disable:
+            self.desc = ""
         if not self.desc:
             self.set_description(trans._("progress"))
         progress._all_instances.add(self)


Test patch:
diff --git a/napari/utils/_tests/test_progress.py b/napari/utils/_tests/test_progress.py
--- a/napari/utils/_tests/test_progress.py
+++ b/napari/utils/_tests/test_progress.py
@@ -88,6 +88,18 @@ def test_progress_set_description():
     assert pbr not in progress._all_instances
 
 
+def test_progress_set_disable():
+    """Test that the progress bar does not throw an attribute error when it is disabled."""
+    # before the changes in #5964 this failed with an AttributeError, because self.desc was not
+    # set in the super constructor of tqdm
+    pbr = progress(
+        total=5, disable=True, desc="This description will not be set by tqdm."
+    )
+    # make sure the dummy desscription (empty string) was set
+    assert pbr.desc == "progress: "
+    pbr.close()
+
+
 def test_progrange():
     """Test progrange shorthand for progress(range(n))"""
     with progrange(10) as pbr, progress(range(10)) as pbr2: