Skip to content

Commit dec96ef

Browse files
committed
Replace Struct with a dataclass
1 parent 81eb0a5 commit dec96ef

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-
import platform
44-
import os
45-
import sys
4643
import curses
44+
import errno
45+
import functools
4746
import math
47+
import os
48+
import platform
4849
import re
49-
import time
50-
import functools
51-
5250
import struct
51+
import sys
52+
import time
53+
import unicodedata
54+
from dataclasses import dataclass
5355

5456
if platform.system() != "Windows":
5557
import signal # Windows does not have job control
5658
import termios # Windows uses curses
5759
import fcntl # Windows uses curses
58-
import unicodedata
59-
import errno
6060

6161

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

6969
# This for config
70-
from .config import Struct, getpreferredencoding
70+
from .config import getpreferredencoding
7171

7272
# This for keys
7373
from .keys import cli_key_dispatch as key_dispatch
@@ -90,6 +90,13 @@
9090
# ---
9191

9292

93+
@dataclass
94+
class ShowListState:
95+
cols: int = 0
96+
rows: int = 0
97+
wl: int = 0
98+
99+
93100
def calculate_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
def show_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-
class Struct:
46-
"""Simple class for instantiating objects we can add arbitrary attributes
47-
to and use for various arbitrary things."""
48-
49-
5045
def getpreferredencoding() -> str:
5146
"""Get the user's preferred encoding."""
5247
return locale.getpreferredencoding() or sys.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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy