Skip to content

Commit 50067e0

Browse files
committed
Introduce types.Final annotation
1 parent 07db717 commit 50067e0

File tree

8 files changed

+30
-25
lines changed

8 files changed

+30
-25
lines changed

trepan/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@
3737
import os
3838
import sys
3939
import traceback
40-
from typing import Callable, Literal, Optional
40+
from typing import Callable, Final, Optional
4141

4242
from trepan.debugger import Trepan, debugger_obj
4343
from trepan.interfaces.server import ServerInterface
4444
from trepan.lib.default import DEBUGGER_SETTINGS
4545
from trepan.post_mortem import post_mortem_excepthook, uncaught_exception
4646

47-
DEFAULT_DEBUG_PORT: Literal[1955] = 1955
47+
DEFAULT_DEBUG_PORT: Final[int] = 1955
4848

4949

5050
def debug(

trepan/bwprocessor/main.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
#
3-
# Copyright (C) 2008-2010, 2013-2016, 2023 Rocky Bernstein <rocky@gnu.org>
3+
# Copyright (C) 2008-2010, 2013-2016, 2023, 2025 Rocky Bernstein <rocky@gnu.org>
44
#
55
# This program is free software: you can redistribute it and/or modify
66
# it under the terms of the GNU General Public License as published by
@@ -19,6 +19,7 @@
1919
import sys
2020
import traceback
2121
from reprlib import Repr
22+
from typing import Final
2223

2324
import pyficache
2425

@@ -76,7 +77,7 @@ def resolve_name(obj, command_name):
7677

7778

7879
# Default settings for command processor method call
79-
DEFAULT_PROC_OPTS = {
80+
DEFAULT_PROC_OPTS: Final = {
8081
# A list of debugger initialization files to read on first command
8182
# loop entry. Often this something like [~/.trepanrc] which the
8283
# front-end sets.

trepan/client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python3
22
# -*- coding: utf-8 -*-
33
#
4-
# Copyright (C) 2009, 2013-2017, 2021, 2023-2024 Rocky Bernstein
4+
# Copyright (C) 2009, 2013-2017, 2021, 2023-2025 Rocky Bernstein
55
#
66
# This program is free software; you can redistribute it and/or modify
77
# it under the terms of the GNU General Public License as published by
@@ -21,6 +21,7 @@
2121
import sys
2222
import time
2323
from optparse import OptionParser
24+
from typing import Final
2425

2526
# Our local modules
2627
from trepan.api import DEFAULT_DEBUG_PORT
@@ -88,7 +89,7 @@ def process_options(pkg_version, sys_argv, option_list=None):
8889
#
8990

9091
# DEFAULT_CLIENT_CONNECTION_OPTS = {'open': True, 'IO': 'FIFO'}
91-
DEFAULT_CLIENT_CONNECTION_OPTS = {
92+
DEFAULT_CLIENT_CONNECTION_OPTS: Final = {
9293
"open": True,
9394
"IO": "TCP",
9495
"HOST": "127.0.0.1",

trepan/inout/fifoclient.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
#
3-
# Copyright (C) 2009, 2013-2015, 2023 Rocky Bernstein
3+
# Copyright (C) 2009, 2013-2015, 2023, 2025 Rocky Bernstein
44
# <rocky@gnu.org>
55
#
66
# This program is free software: you can redistribute it and/or modify
@@ -20,6 +20,7 @@
2020
import os
2121
import tempfile
2222

23+
from typing import Final
2324
from trepan import misc as Mmisc
2425
from trepan.inout.base import DebuggerInOutBase
2526
from trepan.lib import default as Mdefault, file as Mfile
@@ -28,7 +29,7 @@
2829
class FIFOClient(DebuggerInOutBase):
2930
"""Debugger Client Input/Output Socket."""
3031

31-
DEFAULT_INIT_OPTS = {"open": True}
32+
DEFAULT_INIT_OPTS: Final = {"open": True}
3233

3334
def __init__(self, inp=None, opts=None):
3435
get_option = lambda key: Mmisc.option_set(

trepan/inout/fifoserver.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
# Copyright (C) 2009, 2013-2015 Rocky Bernstein <rocky@gnu.org>
2+
# Copyright (C) 2009, 2013-2015, 2025 Rocky Bernstein <rocky@gnu.org>
33
#
44
# This program is free software: you can redistribute it and/or modify
55
# it under the terms of the GNU General Public License as published by
@@ -13,25 +13,26 @@
1313
#
1414
# You should have received a copy of the GNU General Public License
1515
# along with this program. If not, see <http://www.gnu.org/licenses/>.
16-
"""Debugger FIFO Input/Output interface. """
16+
"""Debugger FIFO Input/Output interface."""
1717

1818
import os
19+
from typing import Final
1920

2021
if hasattr(os, "mkfifo"):
2122
import atexit
2223
import tempfile
2324

24-
from trepan import misc as Mmisc
25+
from trepan.misc import option_set
2526
from trepan.inout.base import DebuggerInOutBase
2627

2728
# FIXME: Consider using Python's socketserver/SocketServer?
2829
class FIFOServer(DebuggerInOutBase):
2930
"""Debugger Server Input/Output Socket."""
3031

31-
DEFAULT_INIT_OPTS = {"open": True}
32+
DEFAULT_INIT_OPTS: Final = {"open": True}
3233

3334
def __init__(self, opts=None):
34-
get_option = lambda key: Mmisc.option_set(opts, key, self.DEFAULT_INIT_OPTS)
35+
get_option = lambda key: option_set(opts, key, self.DEFAULT_INIT_OPTS)
3536
atexit.register(self.close)
3637
self.flush_after_write = True
3738
self.line_edit = False # Our name for GNU readline capability

trepan/inout/tcpclient.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
# Copyright (C) 2009, 2013-2015 Rocky Bernstein <rocky@gnu.org>
2+
# Copyright (C) 2009, 2013-2015, 2025 Rocky Bernstein <rocky@gnu.org>
33
#
44
# This program is free software: you can redistribute it and/or modify
55
# it under the terms of the GNU General Public License as published by
@@ -16,8 +16,9 @@
1616
"""Debugger Socket Input/Output Interface."""
1717

1818
import socket
19+
from typing import Final
1920

20-
from trepan.lib import default as Mdefault
21+
from trepan.lib.default import CLIENT_SOCKET_OPTS
2122
from trepan.inout import tcpfns as Mtcpfns
2223
from trepan.inout.base import DebuggerInOutBase
2324
from trepan.misc import option_set
@@ -26,10 +27,10 @@
2627
class TCPClient(DebuggerInOutBase):
2728
"""Debugger Client Input/Output Socket."""
2829

29-
DEFAULT_INIT_OPTS = {"open": True}
30+
DEFAULT_INIT_OPTS: Final = {"open": True}
3031

3132
def __init__(self, inout=None, opts=None):
32-
get_option = lambda key: option_set(opts, key, Mdefault.CLIENT_SOCKET_OPTS)
33+
get_option = lambda key: option_set(opts, key, CLIENT_SOCKET_OPTS)
3334
self.inout = None
3435
self.addr = None
3536
self.buf = ""
@@ -52,13 +53,13 @@ def close(self):
5253

5354
def open(self, opts=None):
5455

55-
get_option = lambda key: option_set(opts, key, Mdefault.CLIENT_SOCKET_OPTS)
56+
get_option = lambda key: option_set(opts, key, CLIENT_SOCKET_OPTS)
5657

5758
HOST = get_option("HOST")
5859
PORT = get_option("PORT")
5960
self.inout = None
6061
for res in socket.getaddrinfo(HOST, PORT, socket.AF_UNSPEC, socket.SOCK_STREAM):
61-
af, socktype, proto, canonname, sa = res
62+
af, socktype, proto, _, sa = res
6263
try:
6364
self.inout = socket.socket(af, socktype, proto)
6465
self.state = "connected"
@@ -72,7 +73,6 @@ def open(self, opts=None):
7273
self.inout.close()
7374
self.inout = None
7475
continue
75-
break
7676
if self.inout is None:
7777
raise IOError("could not open client socket on port %s" % PORT)
7878
return

trepan/inout/tcpserver.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
# Copyright (C) 2009, 2013-2014, 2016-2017 Rocky Bernstein <rocky@gnu.org>
2+
# Copyright (C) 2009, 2013-2014, 2016-2017, 2025 Rocky Bernstein <rocky@gnu.org>
33
#
44
# This program is free software: you can redistribute it and/or modify
55
# it under the terms of the GNU General Public License as published by
@@ -17,6 +17,7 @@
1717

1818
import socket, errno
1919

20+
from typing import Final
2021
from trepan.lib import default as Mdefault
2122
from trepan import misc as Mmisc
2223
from trepan.inout import tcpfns as Mtcpfns
@@ -27,7 +28,7 @@
2728
class TCPServer(DebuggerInOutBase):
2829
"""Debugger Server Input/Output Socket."""
2930

30-
DEFAULT_INIT_OPTS = {"open": True, "socket": None}
31+
DEFAULT_INIT_OPTS: Final = {"open": True, "socket": None}
3132

3233
def __init__(self, inout=None, opts=None):
3334
get_option = lambda key: Mmisc.option_set(opts, key, self.DEFAULT_INIT_OPTS)

trepan/processor/parse/parser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2017-2018 Rocky Bernstein
1+
# Copyright (c) 2017-2018, 2025 Rocky Bernstein
22
"""
33
Parsing for a trepan2/trepan3k debugger
44
"breakpoint' or "list" command arguments
@@ -8,7 +8,7 @@
88
- a range or count for "list" commands
99
"""
1010

11-
from __future__ import print_function
11+
from typing import Final
1212

1313
import sys
1414
from spark_parser.ast import AST
@@ -17,7 +17,7 @@
1717

1818
from spark_parser import GenericASTBuilder
1919

20-
DEFAULT_DEBUG = {
20+
DEFAULT_DEBUG: Final = {
2121
"rules": False,
2222
"transition": False,
2323
"reduce": False,

0 commit comments

Comments
 (0)