11#!/usr/bin/env python3
2-
2+ from __future__ import annotations
33import os
4- from typing import List
4+ from typing import TYPE_CHECKING
55
66import src .api .config
77import src .api .global_ as gl
88from src import arch
99from src .api import debug , errmsg
1010from src .api .config import OPTIONS
1111from src .api .utils import open_file
12- from src .zxbc import args_parser , zxbparser
12+ from src .zxbc import args_parser
13+
14+ if TYPE_CHECKING :
15+ from argparse import Namespace
1316
1417__all__ = ["FileType" , "parse_options" , "set_option_defines" ]
1518
@@ -21,7 +24,7 @@ class FileType:
2124 TZX = "tzx"
2225
2326
24- def parse_options (args : List [str ] = None ):
27+ def parse_options (args : list [str ] | None = None ) -> Namespace :
2528 """Parses command line options and setup global Options container"""
2629 parser = args_parser .parser ()
2730 options = parser .parse_args (args = args )
@@ -56,7 +59,6 @@ def parse_options(args: List[str] = None):
5659
5760 if options .arch not in arch .AVAILABLE_ARCHITECTURES :
5861 parser .error (f"Invalid architecture '{ options .arch } '" )
59- return 2
6062
6163 OPTIONS .architecture = options .arch
6264
@@ -67,7 +69,6 @@ def parse_options(args: List[str] = None):
6769
6870 if duplicated_options :
6971 parser .error (f"Warning(s) { ', ' .join (duplicated_options )} cannot be enabled " f"and disabled simultaneously" )
70- return 2
7172
7273 for warn_code in enabled_warnings :
7374 errmsg .enable_warning (warn_code )
@@ -103,15 +104,12 @@ def parse_options(args: List[str] = None):
103104
104105 if options .basic and not options .tzx and not options .tap :
105106 parser .error ("Option --BASIC and --autorun requires --tzx or tap format" )
106- return 4
107107
108108 if options .append_binary and not options .tzx and not options .tap :
109109 parser .error ("Option --append-binary needs either --tap or --tzx" )
110- return 5
111110
112111 if options .asm and options .memory_map :
113112 parser .error ("Option --asm and --mmap cannot be used together" )
114- return 6
115113
116114 OPTIONS .use_basic_loader = options .basic
117115 OPTIONS .autorun = options .autorun
@@ -128,12 +126,11 @@ def parse_options(args: List[str] = None):
128126 args = [options .PROGRAM ]
129127 if not os .path .exists (options .PROGRAM ):
130128 parser .error ("No such file or directory: '%s'" % args [0 ])
131- return 2
132129
133130 set_option_defines ()
134131
135132 OPTIONS .include_path = options .include_path
136- OPTIONS .input_filename = zxbparser . FILENAME = os .path .basename (args [0 ])
133+ OPTIONS .input_filename = os .path .basename (args [0 ])
137134
138135 if not OPTIONS .output_filename :
139136 OPTIONS .output_filename = (
@@ -146,7 +143,7 @@ def parse_options(args: List[str] = None):
146143 return options
147144
148145
149- def set_option_defines ():
146+ def set_option_defines () -> None :
150147 """Sets some macros automatically, according to options"""
151148 if OPTIONS .memory_check :
152149 OPTIONS .__DEFINES ["__MEMORY_CHECK__" ] = ""
0 commit comments