From 2abf2297aabb355b72c6ae9e0aaf350f7a6cbe9d Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Thu, 17 Apr 2025 12:23:38 +0200 Subject: Add type hints and refactor a bit to please pylint. --- administrative-codes/csv2json | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'administrative-codes/csv2json') diff --git a/administrative-codes/csv2json b/administrative-codes/csv2json index 7c22666..6dd6ad7 100755 --- a/administrative-codes/csv2json +++ b/administrative-codes/csv2json @@ -18,6 +18,8 @@ # along with this program. If not, see . #---------------------------------------------------------------------- +# pylint: disable=missing-module-docstring + import sys import csv from pathlib import Path @@ -25,13 +27,14 @@ import json basedir = Path(sys.argv[0]).parent data = {} -def readCSV(path): - with open(path, mode='r', newline='') as fp: +def readCSV(pathname): # pylint: disable=invalid-name + """Read CSV""" + with open(pathname, mode='r', newline='', encoding='utf-8') as fp: reader = csv.DictReader(fp, delimiter='\t', dialect='unix') for row in reader: code = row['Code'] if code in data: - raise Exception(f'Duplicate code {code}') + raise RuntimeError(f'Duplicate code {code}') data[code] = row['Name'] # The source (SCB) lists all codes in same file: they differ only in -- cgit v1.2.3