internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: napari/napari

Issue:
New surface shaders are broken
## 🐛 Bug

With `0.4.9rc0`, new shaders for mesh rendering were added (#2792).
On my machine, this broke surface layers:

## To Reproduce
```python
import napari
import numpy as np
pos = np.array([[0, 0, 0], [1, 1, 1], [0, 1, 0]]) * 10
faces = np.array([[0, 1, 2]])
v = napari.Viewer(ndisplay=3)
v.add_surface((pos, faces))
```
This fails with a [long trace](https://pastebin.com/ZjCNNRfi), whose starting point seems to be:
```python
File "~/.local/lib/python3.9/site-packages/napari/_vispy/vendored/filters/mesh.py", line 301, in _update_data
    if not self._attached:
AttributeError: 'ShadingFilter' object has no attribute '_attached'
```
and ends with
```python
RuntimeError: Cannot draw program if code has not been set
```

## Environment

```yaml
napari: 0.4.9rc0
Platform: Linux-5.12.8-arch1-1-x86_64-with-glibc2.33
System: Arch Linux
Python: 3.9.5 (default, May 24 2021, 12:50:35) [GCC 11.1.0]
Qt: 5.15.2
PyQt5: 5.15.4
NumPy: 1.20.3
SciPy: 1.6.3
Dask: 2020.12.0
VisPy: 0.6.6

OpenGL:
- GL version: 4.6.0 NVIDIA 465.31
- MAX_TEXTURE_SIZE: 16384

Screens:
- screen 1: resolution 1920x1080, scale 1.0
- screen 2: resolution 1920x1200, scale 1.0

Plugins:
- animation: 0.0.2
- console: 0.0.3
- mrcfile-reader: 0.1.2
- napari-em-reader: 0.1.0
- napari-properties-plotter: 0.1.dev2+g2734460.d20210520
- ndtiffs: 0.1.1
- scikit-image: 0.4.8
- svg: 0.1.5
```


Discussion:
Hmm, ok yeah, I'm getting some problems with the new surface layer too (i.e. try running `python examples/nD_surface.py` and `python examples/add_surface_2D.py`. My real world cryoET dataset still works though, but not sure what's different about that dataset. I do get some errors there when `viewer.dims.ndisplay=2`.

Maybe @alisterburt can look into this. Great job catching @brisvag, we'll wait until we have this fixed to make another rc 

Resolving patch:
diff --git a/napari/_vispy/vispy_surface_layer.py b/napari/_vispy/vispy_surface_layer.py
--- a/napari/_vispy/vispy_surface_layer.py
+++ b/napari/_vispy/vispy_surface_layer.py
@@ -36,7 +36,10 @@ def _on_data_change(self, event=None):
             vertex_values = np.array([0])
         else:
             # Offsetting so pixels now centered
-            vertices = self.layer._data_view[:, ::-1]
+            # coerce to float to solve vispy/vispy#2007
+            vertices = np.asarray(
+                self.layer._data_view[:, ::-1], dtype=np.float32
+            )
             faces = self.layer._view_faces
             vertex_values = self.layer._view_vertex_values
 


Test patch:
Repository: napari/napari

Issue:
Regression on plugin hookspec sorter styling in preferences 
## 🐛 Bug

There seems to be a regression with the styling of the hookspec sorter in the preferences.

I get a lot of

```
WARNING: QPainter::begin: A paint device can only be painted by one painter at a time.
18:13:18 WARNING QPainter::begin: A paint device can only be painted by one painter at a time.
```

and if I uncheck one of the reader hookspecs it goes away instead of being dimmed. Maybe this was from the recent opactiy adjustment in #2783 cc @ppwadhwa @goanpeca 

<img width="1061" alt="Screen Shot 2021-06-03 at 6 13 21 PM" src="https://user-images.githubusercontent.com/6531703/120731117-c63e2780-c497-11eb-84ec-38287d4560db.png">



Discussion:
yes, that's from that PR. I will look at it now!

Resolving patch:
diff --git a/napari/_qt/dialogs/preferences_dialog.py b/napari/_qt/dialogs/preferences_dialog.py
--- a/napari/_qt/dialogs/preferences_dialog.py
+++ b/napari/_qt/dialogs/preferences_dialog.py
@@ -263,7 +263,11 @@ def build_page_dialog(self, schema, values):
                 SETTINGS._env_settings.get(section, {}).get(name, None)
             )
             widget.setDisabled(disable)
-            widget.opacity.setOpacity(0.3 if disable else 1)
+            try:
+                widget.opacity.setOpacity(0.3 if disable else 1)
+            except AttributeError:
+                # some widgets may not have opacity (such as the QtPluginSorter)
+                pass
 
         # set state values for widget
         form.widget.state = values
diff --git a/napari/_vendor/qt_json_builder/qt_jsonschema_form/widgets.py b/napari/_vendor/qt_json_builder/qt_jsonschema_form/widgets.py
--- a/napari/_vendor/qt_json_builder/qt_jsonschema_form/widgets.py
+++ b/napari/_vendor/qt_json_builder/qt_jsonschema_form/widgets.py
@@ -163,10 +163,7 @@ def state(self, state: int):
 
     def configure(self):
         self.hook_list.order_changed.connect(self.on_changed.emit)
-        self.opacity = QtWidgets.QGraphicsOpacityEffect(self)
-        self.setGraphicsEffect(self.opacity)
-        self.opacity.setOpacity(1)
-
+        
     def setDescription(self, description: str):
         self.description = description
 


Test patch:
Repository: napari/napari

Issue:
Tifffile: Compress kwarg  deprecated  in favor of compression
## 🧰 Task

new version of tifffile now emits a DeprecationWarning since version  2021.6.6 that `compression` should be used instead of `compress` in imwrite and alike.



Discussion:

Resolving patch:
diff --git a/napari/utils/io.py b/napari/utils/io.py
--- a/napari/utils/io.py
+++ b/napari/utils/io.py
@@ -1,6 +1,7 @@
 import csv
 import os
 import re
+import warnings
 from glob import glob
 from pathlib import Path
 from typing import List, Optional, Tuple, Union
@@ -28,7 +29,24 @@ def imsave(filename: str, data: np.ndarray):
     if ext in [".tif", ".tiff"]:
         import tifffile
 
-        tifffile.imsave(filename, data, compress=1)
+        compression_instead_of_compress = False
+        try:
+            current_version = tuple(
+                int(x) for x in tifffile.__version__.split('.')[:3]
+            )
+            compression_instead_of_compress = current_version >= (2021, 6, 6)
+        except Exception:
+            # Just in case anything goes wrong in parsing version number
+            # like repackaging on linux or anything else we fallback to
+            # using compress
+            warnings.warn(
+                f'Error parsing tiffile version number {tifffile.__version__:!r}'
+            )
+
+        if compression_instead_of_compress:
+            tifffile.imsave(filename, data, compression=1)
+        else:  # older version of tifffile since 2021.6.6  this is deprecated
+            tifffile.imsave(filename, data, compress=1)
     else:
         import imageio
 


Test patch:
Repository: napari/napari

Issue:
ipython + visible console results in AttributeError
## 🐛 Bug

When instantiating a napari viewer with a visible console dock from inside ipython results in `AttributeError` (seems to be something related to `ipython` itself, see below)

## To Reproduce

Steps to reproduce the behavior:

1. start napari from command line `napari`
2. select the console dock to be visible and close again
3. start napari from within ipython `ipython -c "import napari;napari.Viewer()"`


```
napari/_qt/qt_viewer.py in <lambda>(visible)
    173         # gets (or creates) the console when the dock console is made visible.
    174         self.dockConsole.visibilityChanged.connect(
--> 175             lambda visible: self.console if visible else None
    176         )
    177         self.dockLayerControls.visibilityChanged.connect(self._constrain_width)

AttributeError: 'QtViewer' object has no attribute 'console'
```

This does *not* happen, when
*  the console dock is not visible
*  using `python` instead of `ipython`, i.e. `python -c "import napari;napari.Viewer()"` works

## Expected behavior



## Environment
```
napari: 0.4.9
Platform: macOS-10.15.7-x86_64-i386-64bit
System: MacOS 10.15.7
Python: 3.8.0 (default, Nov 6 2019, 15:49:01) [Clang 4.0.1 (tags/RELEASE_401/final)]
Qt: 5.15.2
PyQt5: 5.15.4
NumPy: 1.20.3
SciPy: 1.6.3
Dask: 2021.06.0
VisPy: 0.6.6

OpenGL:
- GL version: 2.1 ATI-3.10.18
- MAX_TEXTURE_SIZE: 16384

Screens:
- screen 1: resolution 1792x1120, scale 2.0

Plugins:
- console: 0.0.3
- scikit-image: 0.4.9
- svg: 0.1.5
```

## Additional context

happens too on linux and python 3.8/3.9



Discussion:
thanks @maweigert .  git blame puts it at #2861 ... will have a look

Resolving patch:
diff --git a/napari/_qt/qt_viewer.py b/napari/_qt/qt_viewer.py
--- a/napari/_qt/qt_viewer.py
+++ b/napari/_qt/qt_viewer.py
@@ -355,7 +355,9 @@ def console(self):
                 import napari
 
                 self.console = QtConsole(self.viewer)
-                self.console.push({'napari': napari})
+                self.console.push(
+                    {'napari': napari, 'action_manager': action_manager}
+                )
             except ImportError:
                 warnings.warn(
                     trans._(
@@ -372,8 +374,6 @@ def console(self, console):
         if console is not None:
             self.dockConsole.setWidget(console)
             console.setParent(self.dockConsole)
-        if getattr(self, '_console', None) is not None:
-            self._console.shell.user_ns['action_manager'] = action_manager
 
     def _constrain_width(self, event):
         """Allow the layer controls to be wider, only if floated.


Test patch:
Repository: napari/napari

Issue:
Pin vispy < 0.7
## 🚀 Feature
I think we should pin vispy < 0.7 for our next release. Everyone is working hard to ensure a migration will be easy, but there might be some breaking changes when the release comes out, and I think we'll want to be able to adopt 0.7 when we have everything working as expected. 



Discussion:

Resolving patch:
diff --git a/napari/_vispy/vispy_camera.py b/napari/_vispy/vispy_camera.py
--- a/napari/_vispy/vispy_camera.py
+++ b/napari/_vispy/vispy_camera.py
@@ -106,6 +106,8 @@ def zoom(self):
             scale = np.array(
                 [self._view.camera.rect.width, self._view.camera.rect.height]
             )
+            if np.allclose(scale, [0, 0]):  # fix for #2875
+                scale = [1, 1]
         zoom = np.min(canvas_size / scale)
         return zoom
 


Test patch:
Repository: napari/napari

Issue:
Notification can't be expanded and slowly moves off screen
## 🐛 Bug

This is an odd bug I discovered while playing with other things this week. On Ubuntu when I expand a notification it doesn't expand but rather move further down the screen with each click of the arrow. Has anyone else seen this?? I'll investigate it this coming sprint.


https://user-images.githubusercontent.com/17995243/123702615-b521e400-d8a6-11eb-87ca-18c9f323445e.mp4



## To Reproduce

Steps to reproduce the behavior:

1. Open napari
2. Try to open a text file or generate a notification in some other way
3. Try to expand and contract the notification

## Expected behavior

Notification is expanded and contracted, and doesn't move off screen.

## Environment

```
napari: 0.4.9
Platform: Linux-5.4.0-77-generic-x86_64-with-glibc2.17
System: Ubuntu 20.04.2 LTS
Python: 3.8.10 (default, Jun 4 2021, 15:09:15) [GCC 7.5.0]
Qt: 5.15.2
PyQt5: 5.15.4
NumPy: 1.20.3
SciPy: 1.6.3
Dask: 2021.06.0
VisPy: 0.6.6

OpenGL:
- GL version: 4.6 (Compatibility Profile) Mesa 20.2.6
- MAX_TEXTURE_SIZE: 16384

Screens:
- screen 1: resolution 1920x1080, scale 1.0
- screen 2: resolution 1920x515, scale 1.0
- screen 3: resolution 1920x1080, scale 1.0

Plugins:
- console: 0.0.3
- scikit-image: 0.4.9
- svg: 0.1.5
```


Discussion:
I have seen this, but I can't remember how I got there in the first place!
@goanpeca just glad it's not only me :laughing: 

Resolving patch:
diff --git a/napari/_qt/dialogs/qt_notification.py b/napari/_qt/dialogs/qt_notification.py
--- a/napari/_qt/dialogs/qt_notification.py
+++ b/napari/_qt/dialogs/qt_notification.py
@@ -76,6 +76,7 @@ class NapariQtNotification(QDialog):
     FADE_OUT_RATE = 120
     DISMISS_AFTER = 4000
     MIN_WIDTH = 400
+    MIN_EXPANSION = 18
 
     message: MultilineElidedLabel
     source_label: QLabel
@@ -178,6 +179,9 @@ def expand(self):
         self.geom_anim.setDuration(100)
         self.geom_anim.setStartValue(curr)
         new_height = self.sizeHint().height()
+        if new_height < curr.height():
+            # new height would shift notification down, ensure some expansion
+            new_height = curr.height() + self.MIN_EXPANSION
         delta = new_height - curr.height()
         self.geom_anim.setEndValue(
             QRect(curr.x(), curr.y() - delta, curr.width(), new_height)


Test patch:
Repository: napari/napari

Issue:
self._mode_history seem to be unused on points, shapes and labels.
## 🧰 Task

This seem to have been used for "hold space to XXXX" in the past looking at git log, but seem unused now.
It could be an easy first issue.


Discussion:
It doesn't look like anything reads from this so I'll just remove it.
Likely a remnant of previous functionality! I think it's good to be dropped

Resolving patch:
diff --git a/napari/layers/labels/labels.py b/napari/layers/labels/labels.py
--- a/napari/layers/labels/labels.py
+++ b/napari/layers/labels/labels.py
@@ -253,7 +253,6 @@ def __init__(
         self.color = color
 
         self._mode = Mode.PAN_ZOOM
-        self._mode_history = self._mode
         self._status = self.mode
         self._preserve_labels = False
         self._help = trans._('enter paint or fill mode to edit labels')
diff --git a/napari/layers/points/points.py b/napari/layers/points/points.py
--- a/napari/layers/points/points.py
+++ b/napari/layers/points/points.py
@@ -345,7 +345,6 @@ def __init__(
         self._value = None
         self._value_stored = None
         self._mode = Mode.PAN_ZOOM
-        self._mode_history = self._mode
         self._status = self.mode
         self._highlight_index = []
         self._highlight_box = None
diff --git a/napari/layers/shapes/shapes.py b/napari/layers/shapes/shapes.py
--- a/napari/layers/shapes/shapes.py
+++ b/napari/layers/shapes/shapes.py
@@ -255,8 +255,6 @@ class Shapes(Layer):
         Dictionary containing all the shape data indexed by slice tuple
     _data_view : ShapeList
         Object containing the currently viewed shape data.
-    _mode_history : Mode
-        Interactive mode captured on press of <space>.
     _selected_data_history : set
         Set of currently selected captured on press of <space>.
     _selected_data_stored : set
@@ -516,7 +514,6 @@ def __init__(
         # Mode setting logic
         self._mode = Mode.SELECT
         self.mode = Mode.PAN_ZOOM
-        self._mode_history = self._mode
         self._status = self.mode
 
         self._init_shapes(


Test patch:
Repository: napari/napari

Issue:
Opacity slider label should be between 0 and 1
## 🐛 Bug

Opacity slider label should be between 0 and 1 not 0 and 100. This will remove need for normalization on slider https://github.com/napari/napari/blob/aade148d8e5cb339bb2981ab4d1081ae5d2747e0/napari/_qt/layer_controls/qt_layer_controls_base.py#L79

![image](https://user-images.githubusercontent.com/6531703/125152865-96bcb380-e104-11eb-9a09-7a9784a3da0c.png)




Discussion:
Hasn't line 79 solved the issue?

Resolving patch:
diff --git a/napari/_qt/layer_controls/qt_layer_controls_base.py b/napari/_qt/layer_controls/qt_layer_controls_base.py
--- a/napari/_qt/layer_controls/qt_layer_controls_base.py
+++ b/napari/_qt/layer_controls/qt_layer_controls_base.py
@@ -1,6 +1,6 @@
 from qtpy.QtCore import Qt
 from qtpy.QtWidgets import QComboBox, QFrame, QGridLayout
-from superqt import QLabeledSlider as QSlider
+from superqt import QLabeledDoubleSlider
 
 from ...layers.base._base_constants import BLENDING_TRANSLATIONS
 from ...utils.events import disconnect_events
@@ -47,11 +47,11 @@ def __init__(self, layer):
         self.grid_layout.setColumnStretch(1, 1)
         self.setLayout(self.grid_layout)
 
-        sld = QSlider(Qt.Horizontal, parent=self)
+        sld = QLabeledDoubleSlider(Qt.Horizontal, parent=self)
         sld.setFocusPolicy(Qt.NoFocus)
         sld.setMinimum(0)
-        sld.setMaximum(100)
-        sld.setSingleStep(1)
+        sld.setMaximum(1)
+        sld.setSingleStep(0.01)
         sld.valueChanged.connect(self.changeOpacity)
         self.opacitySlider = sld
         self._on_opacity_change()
@@ -76,7 +76,7 @@ def changeOpacity(self, value):
             Input range 0 - 100 (transparent to fully opaque).
         """
         with self.layer.events.blocker(self._on_opacity_change):
-            self.layer.opacity = value / 100
+            self.layer.opacity = value
 
     def changeBlending(self, text):
         """Change blending mode on the layer model.
@@ -97,7 +97,7 @@ def _on_opacity_change(self, event=None):
             The napari event that triggered this method, by default None.
         """
         with self.layer.events.opacity.blocker():
-            self.opacitySlider.setValue(int(self.layer.opacity * 100))
+            self.opacitySlider.setValue(self.layer.opacity)
 
     def _on_blending_change(self, event=None):
         """Receive layer model blending mode change event and update slider.


Test patch:
Repository: napari/napari

Issue:
Decide best way to ship `pyi` files with sdist/wheel
## 🧰 Task
Once #2675 is merged, developers will be able to get type stubs for a couple autogenerated modules by running `make typestubs` in their dev environment.  We still need to figure out the best way to ship those `.pyi` with the sdist... 


Discussion:

Resolving patch:
diff --git a/napari/components/viewer_model.py b/napari/components/viewer_model.py
--- a/napari/components/viewer_model.py
+++ b/napari/components/viewer_model.py
@@ -60,8 +60,10 @@
 EXCLUDE_JSON = EXCLUDE_DICT.union({'layers', 'active_layer'})
 
 if TYPE_CHECKING:
-    from ..types import FullLayerData, LayerData, PathOrPaths
+    from ..types import FullLayerData, LayerData
 
+PathLike = Union[str, Path]
+PathOrPaths = Union[PathLike, Sequence[PathLike]]
 
 __all__ = ['ViewerModel', 'valid_add_kwargs']
 
diff --git a/napari/utils/stubgen.py b/napari/utils/stubgen.py
--- a/napari/utils/stubgen.py
+++ b/napari/utils/stubgen.py
@@ -187,7 +187,4 @@ def generate_module_stub(module: Union[str, ModuleType], save=True) -> str:
     default_modules = ['napari.view_layers', 'napari.components.viewer_model']
 
     for mod in sys.argv[1:] or default_modules:
-        try:
-            generate_module_stub(mod)
-        except Exception as e:
-            print(f"ERROR: {e}")
+        generate_module_stub(mod)
diff --git a/napari/viewer.py b/napari/viewer.py
--- a/napari/viewer.py
+++ b/napari/viewer.py
@@ -28,8 +28,7 @@ class Viewer(ViewerModel):
         Whether to show the viewer after instantiation. by default True.
     """
 
-    # Create private variable for window
-    _window: 'Window'
+    _window: 'Window' = None  # type: ignore
 
     def __init__(
         self,


Test patch:
Repository: napari/napari

Issue:
Consider making default shapes edge-color not black
## 🐛 Bug
The default edge-color of black doesn't work well with a default canvas color of black.
it looks like lines don't work:

https://user-images.githubusercontent.com/1609449/127573341-255a2f03-7459-4c97-90ad-1b0b4296c1a5.mov




Discussion:
Totally agree, I've run into this and it's pretty annoying because you have to select all the shapes and then change the edge colour - new users may not realize. Whatever we choose would obviously still have to work with the light theme where the canvas is white, so maybe a middle grey.

Resolving patch:
diff --git a/napari/layers/shapes/shapes.py b/napari/layers/shapes/shapes.py
--- a/napari/layers/shapes/shapes.py
+++ b/napari/layers/shapes/shapes.py
@@ -385,7 +385,7 @@ def __init__(
         text=None,
         shape_type='rectangle',
         edge_width=1,
-        edge_color='black',
+        edge_color='#777777',
         edge_color_cycle=None,
         edge_colormap='viridis',
         edge_contrast_limits=None,


Test patch:
Repository: napari/napari

Issue:
"Shuffle colors" button in Labels layer controls incorrectly updates the selected label color
## 🐛 Bug

Using the shuffle colors button on the Labels layer shuffles the colors, but the new color displayed next to the selected label spinbox is incorrect. Incrementing and decrementing the spinbox restores the correct color.

## To Reproduce

```python
import napari
import numpy as np

viewer = napari.view_labels(np.array([[1, 2]]))
napari.run()
```

Then:
- click shuffle a few times (until the color clearly doesn't match)
- click - on the selected label spinbox
- click + on the selected label spinbox

<img width="1645" alt="Screen Shot 2021-08-09 at 10 17 02 am" src="https://user-images.githubusercontent.com/492549/128650323-0718c452-66ba-48fb-ae94-c80a62deec11.png">

⬇️ 

<img width="1645" alt="Screen Shot 2021-08-09 at 10 17 10 am" src="https://user-images.githubusercontent.com/492549/128650350-fe5e8365-7e8b-4630-8fff-1e68130cad9f.png">

# napari info

```
napari: 0.4.11.dev80+g954e8a68a.d20210727
Platform: macOS-11.4-x86_64-i386-64bit
System: MacOS 11.4
Python: 3.9.6 | packaged by conda-forge | (default, Jul 11 2021, 03:36:15) [Clang 11.1.0 ]
Qt: 5.15.2
PyQt5: 5.15.4
NumPy: 1.21.1
SciPy: 1.7.0
Dask: 2021.07.1
VisPy: 0.7.3

OpenGL:
- GL version: 2.1 ATI-4.5.14
- MAX_TEXTURE_SIZE: 16384

Screens:
- screen 1: resolution 2304x1296, scale 2.0
- screen 2: resolution 1792x1120, scale 2.0

Plugins:
- aicsimageio-in-memory: 0.3.5
- aicsimageio-out-of-memory: 0.3.5
- bioformats: 0.1.2
- clEsperanto: 0.9.10
- console: 0.0.3
- ome-types: 0.2.7
- ome_zarr: 0.0.17
- platelet-unet-watershed: 0.0.1
- scikit-image: 0.4.11.dev80+g954e8a68a.d20210727
- svg: 0.1.5
- zarpaint: 0.1.1.dev2+gaf11a7a.d20210805
```


Discussion:

Resolving patch:
diff --git a/napari/layers/labels/labels.py b/napari/layers/labels/labels.py
--- a/napari/layers/labels/labels.py
+++ b/napari/layers/labels/labels.py
@@ -385,10 +385,10 @@ def seed(self):
     @seed.setter
     def seed(self, seed):
         self._seed = seed
-        self._selected_color = self.get_color(self.selected_label)
         # invalidate _all_vals to trigger re-generation
         # in _raw_to_displayed
         self._all_vals = np.array([])
+        self._selected_color = self.get_color(self.selected_label)
         self.refresh()
         self.events.selected_label()
 


Test patch:
Repository: napari/napari

Issue:
Bug in _QtMainWindow `window_position` on first resizeEvent
## 🐛 Bug
after #3075, the `resizeEvent` in `_QtMainWindow` seems a bit buggy, and I often find my window pinned in the upper left corner.

I haven't dug too deep, but a pretty repeatable way to see the problem is to open napari, open the console, then close napari.  I believe that the very first `resizeEvent` ends up appending a window position of `(0, -22)`, so if you save after two resize events, it saves that first incorrect window position.

cc @goanpeca 


Discussion:
Thanks @tlambert03, will take a look.
@tlambert03 I cannot reproduce with the steps you mention 🤔 

Resolving patch:
diff --git a/napari/_qt/qt_main_window.py b/napari/_qt/qt_main_window.py
--- a/napari/_qt/qt_main_window.py
+++ b/napari/_qt/qt_main_window.py
@@ -320,12 +320,15 @@ def changeEvent(self, event):
 
     def resizeEvent(self, event):
         """Override to handle original size before maximizing."""
-        self._old_size = event.oldSize()
-        self._positions.append((self.x(), self.y()))
-
-        if self._positions and len(self._positions) >= 2:
-            self._window_pos = self._positions[-2]
-            self._positions = self._positions[-2:]
+        # the first resize event will have nonsense positions that we dont
+        # want to store (and potentially restore)
+        if event.oldSize().isValid():
+            self._old_size = event.oldSize()
+            self._positions.append((self.x(), self.y()))
+
+            if self._positions and len(self._positions) >= 2:
+                self._window_pos = self._positions[-2]
+                self._positions = self._positions[-2:]
 
         super().resizeEvent(event)
 


Test patch: