Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdec96ef

Browse files
committed
Replace Struct with a dataclass
1 parent81eb0a5 commitdec96ef

File tree

4 files changed

+19
-19
lines changed

4 files changed

+19
-19
lines changed

‎bpython/cli.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,23 @@
4040
# - View source doesn't work on windows unless you install the less program (From GnuUtils or Cygwin)
4141

4242

43-
importplatform
44-
importos
45-
importsys
4643
importcurses
44+
importerrno
45+
importfunctools
4746
importmath
47+
importos
48+
importplatform
4849
importre
49-
importtime
50-
importfunctools
51-
5250
importstruct
51+
importsys
52+
importtime
53+
importunicodedata
54+
fromdataclassesimportdataclass
5355

5456
ifplatform.system()!="Windows":
5557
importsignal# Windows does not have job control
5658
importtermios# Windows uses curses
5759
importfcntl# Windows uses curses
58-
importunicodedata
59-
importerrno
6060

6161

6262
# These are used for syntax highlighting
@@ -67,7 +67,7 @@
6767
from .formatterimportBPythonFormatter
6868

6969
# This for config
70-
from .configimportStruct,getpreferredencoding
70+
from .configimportgetpreferredencoding
7171

7272
# This for keys
7373
from .keysimportcli_key_dispatchaskey_dispatch
@@ -90,6 +90,13 @@
9090
# ---
9191

9292

93+
@dataclass
94+
classShowListState:
95+
cols:int=0
96+
rows:int=0
97+
wl:int=0
98+
99+
93100
defcalculate_screen_lines(tokens,width,cursor=0):
94101
"""Given a stream of tokens and a screen width plus an optional
95102
initial cursor position, return the amount of needed lines on the
@@ -1254,11 +1261,7 @@ def write(self, s):
12541261
defshow_list(
12551262
self,items,arg_pos,topline=None,formatter=None,current_item=None
12561263
):
1257-
1258-
shared=Struct()
1259-
shared.cols=0
1260-
shared.rows=0
1261-
shared.wl=0
1264+
shared=ShowListState()
12621265
y,x=self.scr.getyx()
12631266
h,w=self.scr.getmaxyx()
12641267
down=y<h//2

‎bpython/config.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@ def __init__(self, key: str, color: str) -> None:
4242
self.color=color
4343

4444

45-
classStruct:
46-
"""Simple class for instantiating objects we can add arbitrary attributes
47-
to and use for various arbitrary things."""
48-
49-
5045
defgetpreferredencoding()->str:
5146
"""Get the user's preferred encoding."""
5247
returnlocale.getpreferredencoding()orsys.getdefaultencoding()

‎requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Pygments
22
backports.cached-property;python_version<"3.8"
33
curtsies>=0.3.5
44
cwcwidth
5+
dataclasses;python_version<"3.7"
56
greenlet
67
pyxdg
78
requests

‎setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ packages =
2222
install_requires =
2323
backports.cached-property; python_version < "3.8"
2424
curtsies >=0.3.5
25+
dataclasses; python_version < "3.7"
2526
cwcwidth
2627
greenlet
2728
pygments

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp