Skip to content
This repository was archived by the owner on Jan 1, 2026. It is now read-only.

Commit dde9916

Browse files
committed
Switch to PEP484 compatible type hints.
1 parent e120831 commit dde9916

File tree

4 files changed

+28
-12
lines changed

4 files changed

+28
-12
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ python:
55
- 3.3
66
- 2.7
77
install:
8+
- pip install -r requirements.txt
89
- pip install codecov
910
- pip install flake8 pep8-naming flake8-quotes
1011
before_script:

cppcheck_junit.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import argparse
66
import collections
7+
from typing import Dict, List
78
import os
89
import sys
910
from xml.etree import ElementTree
@@ -15,16 +16,24 @@
1516

1617

1718
class CppcheckError(object):
18-
def __init__(self, file, line, message, severity, error_id, verbose):
19+
def __init__(self,
20+
file, # type: str
21+
line, # type: int
22+
message, # type: str
23+
severity, # type: str
24+
error_id, # type: str
25+
verbose # type: str
26+
):
27+
# type: () -> CppcheckError
1928
"""Constructor.
2029
2130
Args:
22-
file (str): File error originated on.
23-
line (int): Line error originated on.
24-
message (str): Error message.
25-
severity (str): Severity of the error.
26-
error_id (str): Unique identifier for the error.
27-
verbose (str): Verbose error message.
31+
file: File error originated on.
32+
line: Line error originated on.
33+
message: Error message.
34+
severity: Severity of the error.
35+
error_id: Unique identifier for the error.
36+
verbose: Verbose error message.
2837
"""
2938
self.file = file
3039
self.line = line
@@ -35,6 +44,7 @@ def __init__(self, file, line, message, severity, error_id, verbose):
3544

3645

3746
def parse_arguments():
47+
# type: () -> argparse.Namespace
3848
parser = argparse.ArgumentParser(
3949
description='Converts Cppcheck XML version 2 to JUnit XML format.\n'
4050
'Usage:\n'
@@ -47,13 +57,14 @@ def parse_arguments():
4757

4858

4959
def parse_cppcheck(file_name):
60+
# type: (str) -> Dict[str, List[CppcheckError]]
5061
"""Parses a Cppcheck XML version 2 file.
5162
5263
Args:
53-
file_name (str): Cppcheck XML file.
64+
file_name: Cppcheck XML file.
5465
5566
Returns:
56-
Dict[str, List[CppcheckError]]: Parsed errors grouped by file name.
67+
Parsed errors grouped by file name.
5768
5869
Raises:
5970
IOError: If file_name does not exist (More specifically, FileNotFoundError on Python 3).
@@ -83,13 +94,14 @@ def parse_cppcheck(file_name):
8394

8495

8596
def generate_test_suite(errors):
97+
# type: (Dict[str, List[CppcheckError]]) -> ElementTree.ElementTree
8698
"""Converts parsed Cppcheck errors into JUnit XML tree.
8799
88100
Args:
89-
errors (Dict[str, List[CppcheckError]]):
101+
errors: Parsed cppcheck errors.
90102
91103
Returns:
92-
ElementTree.ElementTree: XML test suite.
104+
XML test suite.
93105
"""
94106
test_suite = ElementTree.Element('testsuite')
95107
test_suite.attrib['errors'] = str(len(errors))
@@ -115,10 +127,11 @@ def generate_test_suite(errors):
115127

116128

117129
def main(): # pragma: no cover
130+
# type: () -> int
118131
"""Main function.
119132
120133
Returns:
121-
int: Exit code.
134+
Exit code.
122135
"""
123136
args = parse_arguments()
124137

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
typing

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
license='MIT',
1818

1919
py_modules=['cppcheck_junit'],
20+
install_requires=open('requirements.txt').readlines(),
2021
zip_safe=False,
2122

2223
classifiers=[

0 commit comments

Comments
 (0)