Skip to content

Commit

Permalink
Merge pull request #123 from hanjinliu/py312
Browse files Browse the repository at this point in the history
Add python 3.12
  • Loading branch information
hanjinliu authored Oct 3, 2023
2 parents 6edc2f7 + f31e377 commit e202bfd
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
platform: [ubuntu-latest, macos-latest, windows-latest]
backend: [pyqt5]
include:
Expand Down
2 changes: 1 addition & 1 deletion magicclass/fields/_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def __repr__(self):

def __set_name__(self, owner: type, name: str) -> None:
self._parent_class = owner
if name in owner.__annotations__ and self.annotation is None:
if name in getattr(owner, "__annotations__", {}) and self.annotation is None:
self.annotation = owner.__annotations__[name]
if self.name is None:
self.name = name
Expand Down
28 changes: 8 additions & 20 deletions magicclass/widgets/codeedit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import inspect
from typing import Any, Iterator, NamedTuple, TYPE_CHECKING
import weakref
from collections import Counter
from qtpy import QtWidgets as QtW, QtGui, QtCore
from qtpy.QtCore import Qt, Signal as pyqtSignal

Expand Down Expand Up @@ -599,30 +600,17 @@ def _new_line_event(self):

ndel = len(line) - len(line_rstripped)
last_char = line_rstripped[-1]
if last_char in "([{:":
_counter = Counter(line)
_not_closed = (
_counter["("] - _counter[")"] > 0
or _counter["["] - _counter["]"] > 0
or _counter["{"] - _counter["}"] > 0
)
if _not_closed or last_char in "([{:":
for _ in range(ndel):
cursor.deletePreviousChar()
cursor.insertText("\n" + indent + _TAB)
self.setTextCursor(cursor)
cursor = self.textCursor()
if _close := {"(": ")", "{": "}", "[": "]"}.get(last_char):
cursor.movePosition(
QtGui.QTextCursor.MoveOperation.EndOfLine,
QtGui.QTextCursor.MoveMode.KeepAnchor,
)
if (idx := cursor.selectedText().find(_close)) >= 0:
cursor.clearSelection()
for _ in range(idx):
cursor.movePosition(
QtGui.QTextCursor.MoveOperation.NextCharacter,
)
cursor.movePosition(QtGui.QTextCursor.MoveOperation.Left)
cursor.insertText("\n" + indent)
cursor.movePosition(QtGui.QTextCursor.MoveOperation.Up)
cursor.movePosition(QtGui.QTextCursor.MoveOperation.StartOfLine)
cursor.movePosition(QtGui.QTextCursor.MoveOperation.NextWord)
cursor.clearSelection()
self.setTextCursor(cursor)
else:
cursor.insertText("\n" + indent)
self.setTextCursor(cursor)
Expand Down
3 changes: 2 additions & 1 deletion magicclass/widgets/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def appendHref(self, text: str, link: str):
self._emit_output(Output.LINK, linkedStr(text, link))

def _emit_output(self, output: int, obj: Printable):
with suppress(RuntimeError):
with suppress(RuntimeError, OSError):
self.process.emit((output, obj))

def _post_append(self):
Expand Down Expand Up @@ -589,6 +589,7 @@ def set_plt(self, style: str = None, rc_context: dict[str, Any] = {}):
if not show._called:
show()
self.__class__.current_logger = None
plt.close("all")
mpl.use(backend)
return None

Expand Down
3 changes: 2 additions & 1 deletion magicclass/widgets/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ def __init__(
style=None,
**kwargs,
):

if isinstance(nrows, int):
import matplotlib as mpl
import matplotlib.pyplot as plt
Expand All @@ -101,6 +100,7 @@ def __init__(
with plt.style.context(style):
fig, _ = plt.subplots(nrows, ncols, figsize=figsize)
finally:
plt.close("all")
mpl.use(backend)
else:
fig = nrows
Expand Down Expand Up @@ -407,6 +407,7 @@ def func(self: SeabornFigure, *args, **kwargs):
mpl.use("Agg")
grid: Grid = f(self, *args, **kwargs)
finally:
plt.close("all")
mpl.use(backend)

self._reset_canvas(grid.figure)
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ classifiers = [
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]
dynamic = ["version"]
description = "Generate multifunctional GUIs from classes"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_fields.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Annotated
from typing_extensions import Annotated
from magicclass import (
magicclass,
magicmenu,
Expand Down

0 comments on commit e202bfd

Please sign in to comment.