Skip to content

Commit 4c0cc40

Browse files
authored
Merge pull request #293 from gkreitz/fix_mypy_errors
Fix mypy errors
2 parents b85906a + e344d4b commit 4c0cc40

File tree

10 files changed

+33
-43
lines changed

10 files changed

+33
-43
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
*.pyc
22
*~
3+
*.swp
34
/.cache/
45
/problemtools.egg-info/
56
/support/default_validator/default_validator
67
/support/interactive/interactive
78
build/
9+
10+
venv/
11+
.pytest_cache/
12+
.mypy_cache/

mypy.ini

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,5 @@ install_types = True
44
check_untyped_defs = True
55
ignore_errors = False
66

7-
[mypy-problemtools.tests.*]
8-
ignore_errors = True
9-
107
[mypy-problemtools.generatedata]
118
ignore_errors = True
12-
13-
[mypy-problemtools.languages]
14-
ignore_errors = True
15-
16-
[mypy-problemtools.template]
17-
ignore_errors = True
18-
19-
[mypy-problemtools.run.checktestdata]
20-
ignore_errors = True
21-
22-
[mypy-problemtools.run.viva]
23-
ignore_errors = True

problemtools/languages.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def get_source_files(self, file_list):
5252
"""
5353
return [file_name for file_name in file_list
5454
if (any(fnmatch.fnmatch(file_name, glob)
55-
for glob in self.files)
55+
for glob in self.files) # type: ignore[union-attr]
5656
and
5757
self.__matches_shebang(file_name))]
5858

@@ -105,18 +105,13 @@ def __check(self):
105105
"""
106106
# Check that all mandatory fields are provided
107107
if self.name is None:
108-
raise LanguageConfigError(
109-
'Language %s has no name' % self.lang_id)
108+
raise LanguageConfigError(f'Language {self.lang_id} has no name')
110109
if self.priority is None:
111-
raise LanguageConfigError(
112-
'Language %s has no priority' % self.lang_id)
110+
raise LanguageConfigError(f'Language {self.lang_id} has no priority')
113111
if self.files is None:
114-
raise LanguageConfigError(
115-
116-
'Language %s has no files glob' % self.lang_id)
112+
raise LanguageConfigError(f'Language {self.lang_id} has no files glob')
117113
if self.run is None:
118-
raise LanguageConfigError(
119-
'Language %s has no run command' % self.lang_id)
114+
raise LanguageConfigError(f'Language {self.lang_id} has no run command')
120115

121116
# Check that all variables appearing are valid
122117
variables = Language.__variables_in_command(self.run)

problemtools/run/checktestdata.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ def do_compile(self) -> tuple[bool, str|None]:
4141
return ((os.WIFEXITED(status) and os.WEXITSTATUS(status) in [0, 1]), None)
4242

4343

44-
def run(self, infile='/dev/null', outfile='/dev/null',
45-
errfile='/dev/null', args=None, timelim=1000):
44+
def run(self, infile='/dev/null', outfile='/dev/null', errfile='/dev/null',
45+
args=None, timelim=1000, memlim=1024, work_dir=None):
4646
"""Run the Checktestdata script to validate an input file.
4747
4848
Args:
@@ -66,7 +66,9 @@ def run(self, infile='/dev/null', outfile='/dev/null',
6666
outfile=outfile,
6767
errfile=errfile,
6868
args=args,
69-
timelim=timelim)
69+
timelim=timelim,
70+
memlim=memlim,
71+
work_dir=work_dir)
7072
# This is ugly, switches the accept exit status and our accept
7173
# exit status 42.
7274
if os.WIFEXITED(status) and os.WEXITSTATUS(status) == 0:

problemtools/run/program.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def run(self, infile='/dev/null', outfile='/dev/null', errfile='/dev/null',
3434
Args:
3535
infile (str): name of file to pass on stdin
3636
outfile (str): name of file to send stdout to
37-
errfile (str): name of file to send stderr ro
37+
errfile (str): name of file to send stderr to
3838
args (list of str): additional command-line arguments to
3939
pass to the program
4040
timelim (int): CPU time limit in seconds

problemtools/run/viva.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ def do_compile(self) -> tuple[bool, str|None]:
4040
return ((os.WIFEXITED(status) and os.WEXITSTATUS(status) == 0), None)
4141

4242

43-
def run(self, infile='/dev/null', outfile='/dev/null',
44-
errfile='/dev/null', args=None, timelim=1000):
43+
def run(self, infile='/dev/null', outfile='/dev/null', errfile='/dev/null',
44+
args=None, timelim=1000, memlim=1024, work_dir=None):
4545
"""Run the VIVA script to validate an input file.
4646
4747
Args:
@@ -68,7 +68,9 @@ def run(self, infile='/dev/null', outfile='/dev/null',
6868
(status, runtime) = super(Viva, self).run(outfile=outfile,
6969
errfile=errfile,
7070
args=args,
71-
timelim=timelim)
71+
timelim=timelim,
72+
memlim=memlim,
73+
work_dir=work_dir)
7274
# This is ugly, switches the accept exit status and our accept
7375
# exit status 42.
7476
if os.WIFEXITED(status) and os.WEXITSTATUS(status) == 0:

problemtools/template.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def __init__(self, problemdir, language=None, force_copy_cls=False, version="aut
3434
if glob.glob(os.path.join(stmtdir, 'problem.tex')):
3535
langs.append('')
3636
for f in glob.glob(os.path.join(stmtdir, 'problem.[a-z][a-z].tex')):
37-
langs.append(re.search("problem.([a-z][a-z]).tex$", f).group(1))
37+
langs.append(re.search("problem.([a-z][a-z]).tex$", f).group(1)) # type: ignore[union-attr]
3838
if len(langs) == 0:
3939
raise Exception('No problem statements available')
4040

@@ -69,10 +69,10 @@ def __init__(self, problemdir, language=None, force_copy_cls=False, version="aut
6969
templatepaths = [os.path.join(os.path.dirname(__file__), 'templates/latex'),
7070
os.path.join(os.path.dirname(__file__), '../templates/latex'),
7171
'/usr/lib/problemtools/templates/latex']
72-
self.templatepath = next((p for p in templatepaths
73-
if os.path.isdir(p) and os.path.isfile(os.path.join(p, self.templatefile))),
74-
None)
75-
if self.templatepath is None:
72+
try:
73+
self.templatepath = next((p for p in templatepaths
74+
if os.path.isdir(p) and os.path.isfile(os.path.join(p, self.templatefile))))
75+
except StopIteration:
7676
raise Exception('Could not find directory with latex template "%s"' % self.templatefile)
7777

7878
self.basedir = os.path.dirname(problemdir)

problemtools/tests/test_languages.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def test_update(self):
3434
assert lang.files == ['*']
3535

3636
lang.update({'shebang': 'new.*end'})
37-
assert lang.shebang.match('newfilend')
37+
assert lang.shebang is not None and lang.shebang.match('newfilend')
3838

3939
with pytest.raises(languages.LanguageConfigError):
4040
# ambiguous entry point
@@ -52,9 +52,9 @@ def test_update(self):
5252
def test_invalid_id(self):
5353
vals = self.__language_dict()
5454
with pytest.raises(TypeError):
55-
languages.Language(None, vals)
55+
languages.Language(None, vals) # type: ignore
5656
with pytest.raises(TypeError):
57-
languages.Language(42, vals)
57+
languages.Language(42, vals) # type: ignore
5858
with pytest.raises(languages.LanguageConfigError):
5959
languages.Language('åäö', vals)
6060
with pytest.raises(languages.LanguageConfigError):

problemtools/tests/test_output_validator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def test_output_validator_feedback():
1313
text = "".join(r.choices(string.printable))
1414
feedback.write_text(text)
1515
data = OutputValidators._get_feedback(directory)
16-
assert text in data
16+
assert data is not None and text in data
1717

1818

1919
def test_output_validator_feedback_non_unicode():

problemtools/tests/test_verify_hello.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ def test_load_hello():
88

99
args = verify.argparser().parse_args([string])
1010
verify.initialize_logging(args)
11+
context = verify.Context(args, None)
1112

1213
with verify.Problem(string) as p:
1314
assert p.shortname == "hello"
1415
# pytest and fork don't go along very well, so just run aspects that work without run
15-
assert p.getProblemPart(verify.ProblemConfig).check(args)
16-
assert p.getProblemPart(verify.Attachments).check(args)
16+
assert p.getProblemPart(verify.ProblemConfig).check(context)
17+
assert p.getProblemPart(verify.Attachments).check(context)

0 commit comments

Comments
 (0)