Skip to content

Commit 3b1822f

Browse files
fix: Add proper type annotations for Optional parameters
- Use Optional[str] for nullable string parameters - Use Optional[Path] for nullable path parameters - Add return type annotations (Optional[object], object) for compile/run methods - Import typing.Optional in all adapter modules - Fixes all Pylance type checking warnings
1 parent 3327f5b commit 3b1822f

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

bootcs/check/adapters/base.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class LanguageAdapter(ABC):
2424
language (str): The programming language (e.g., "c", "python", "java")
2525
"""
2626

27-
def __init__(self, problem: str, language: str = None):
27+
def __init__(self, problem: str, language: Optional[str] = None):
2828
"""
2929
Initialize the language adapter.
3030
@@ -59,7 +59,7 @@ def get_source_file(self) -> Path:
5959
pass
6060

6161
@abstractmethod
62-
def compile(self, *args, **kwargs):
62+
def compile(self, *args, **kwargs) -> Optional[object]:
6363
"""
6464
Compile the source code (if needed for this language).
6565
@@ -72,11 +72,14 @@ def compile(self, *args, **kwargs):
7272
7373
Raises:
7474
CompileError: If compilation fails
75+
76+
Returns:
77+
Optional process object for validation languages
7578
"""
7679
pass
7780

7881
@abstractmethod
79-
def run(self, *args, stdin=None, **kwargs):
82+
def run(self, *args, stdin=None, **kwargs) -> object:
8083
"""
8184
Run the compiled/interpreted program.
8285

bootcs/check/adapters/compiled.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class CompiledLanguageAdapter(LanguageAdapter):
2929
- Java: uses bootcs.check.java module
3030
"""
3131

32-
def __init__(self, problem: str, language: str = None):
32+
def __init__(self, problem: str, language: Optional[str] = None):
3333
"""
3434
Initialize compiled language adapter.
3535
@@ -74,7 +74,7 @@ def get_source_file(self) -> Path:
7474
"""
7575
return find_source_file(self.problem, self.language)
7676

77-
def compile(self, *args, **kwargs):
77+
def compile(self, *args, **kwargs) -> Optional[object]:
7878
"""
7979
Compile the source code using language-specific compiler.
8080
@@ -101,7 +101,7 @@ def compile(self, *args, **kwargs):
101101
f"Compilation not yet implemented for language: {self.language}"
102102
)
103103

104-
def run(self, *args, stdin=None, **kwargs):
104+
def run(self, *args, stdin=None, **kwargs) -> object:
105105
"""
106106
Run the compiled program.
107107
@@ -140,7 +140,7 @@ class InterpretedLanguageAdapter(LanguageAdapter):
140140
These languages don't need compilation but still use naming conventions.
141141
"""
142142

143-
def __init__(self, problem: str, language: str = None):
143+
def __init__(self, problem: str, language: Optional[str] = None):
144144
"""
145145
Initialize interpreted language adapter.
146146
@@ -179,7 +179,7 @@ def compile(self, *args, **kwargs):
179179
# Optionally: py_compile.compile(source_file, doraise=True)
180180
pass
181181

182-
def run(self, *args, stdin=None, **kwargs):
182+
def run(self, *args, stdin=None, **kwargs) -> object:
183183
"""
184184
Run the interpreted program.
185185

bootcs/check/adapters/conventions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"""
99

1010
from pathlib import Path
11+
from typing import Optional
1112
from typing import Dict, Callable
1213

1314

@@ -157,7 +158,7 @@ def get_source_filename(problem: str, language: str) -> str:
157158
return convention(problem)
158159

159160

160-
def find_source_file(problem: str, language: str, search_dir: Path = None) -> Path:
161+
def find_source_file(problem: str, language: str, search_dir: Optional[Path] = None) -> Path:
161162
"""
162163
Find the source file for a problem in a given language.
163164

bootcs/check/adapters/factory.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121

2222

2323
def create_adapter(
24-
problem: str = None,
25-
language: str = None,
24+
problem: Optional[str] = None,
25+
language: Optional[str] = None,
2626
adapter_type: str = 'auto'
2727
) -> LanguageAdapter:
2828
"""

0 commit comments

Comments
 (0)