From baf118f0bf46d43c7165d2972e7344ce6e1bdb7f Mon Sep 17 00:00:00 2001 From: John Pennycook Date: Tue, 30 Jan 2024 07:31:24 -0800 Subject: [PATCH] Add UserWarning for functions taking language=None We can convert None into Language.UNKNOWN automatically, so there is no need to break downstream users of these functions. Signed-off-by: John Pennycook --- codebasin/file_parser.py | 8 ++++++++ codebasin/finder.py | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/codebasin/file_parser.py b/codebasin/file_parser.py index 19aa70f..f00b4b2 100644 --- a/codebasin/file_parser.py +++ b/codebasin/file_parser.py @@ -7,6 +7,7 @@ import logging import os +import warnings from codebasin import preprocessor, util from codebasin.file_source import get_file_source @@ -162,6 +163,13 @@ def parse_file(self, *, summarize_only=True, language=Language.UNKNOWN): Parse the file that this parser points at, build a SourceTree representing this file, and return it. """ + if language is None: + warnings.warn( + "Using a 'language' value of None is deprecated." + + "Please use Language.UNKNOWN instead.", + UserWarning, + ) + language = Language.UNKNOWN filename = self._filename out_tree = preprocessor.SourceTree(filename) diff --git a/codebasin/finder.py b/codebasin/finder.py index 0e115d9..ac52367 100644 --- a/codebasin/finder.py +++ b/codebasin/finder.py @@ -8,6 +8,7 @@ import collections import logging import os +import warnings from codebasin import file_parser, platform, preprocessor, util from codebasin.source import Language @@ -89,6 +90,14 @@ def insert_file(self, fn, language=Language.UNKNOWN): Build a new tree for a source file, and create an association map for it. """ + if language is None: + warnings.warn( + "Using a 'language' value of None is deprecated." + + "Please use Language.UNKNOWN instead.", + UserWarning, + ) + language = Language.UNKNOWN + fn = self._map_filename(fn) if fn not in self.trees: parser = file_parser.FileParser(fn)