Skip to content

Commit

Permalink
Add UserWarning for functions taking language=None
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Pennycook committed Jan 30, 2024
1 parent 9549265 commit baf118f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions codebasin/file_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import logging
import os
import warnings

from codebasin import preprocessor, util
from codebasin.file_source import get_file_source
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions codebasin/finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit baf118f

Please sign in to comment.