MCPcopy
hub / github.com/nltk/nltk / find_deprecated_defs

Function find_deprecated_defs

tools/find_deprecated.py:116–148  ·  view source on GitHub ↗

Return a list of all functions marked with the @deprecated decorator, and classes with an immediate Deprecated base class, in all Python files in the given directory.

(pkg_dir)

Source from the content-addressed store, hash-verified

114
115
116def find_deprecated_defs(pkg_dir):
117 """
118 Return a list of all functions marked with the @deprecated
119 decorator, and classes with an immediate Deprecated base class, in
120 all Python files in the given directory.
121 """
122 # Walk through the directory, finding python files.
123 for root, dirs, files in os.walk(pkg_dir):
124 for filename in files:
125 if filename.endswith(".py"):
126 # Search the file for any deprecated definitions.
127 s = open(os.path.join(root, filename)).read()
128 for m in DEPRECATED_DEF_RE.finditer(s):
129 if m.group(2):
130 name = m.group(2)
131 msg = " ".join(
132 strip_quotes(s) for s in STRING_RE.findall(m.group(1))
133 )
134 msg = " ".join(msg.split())
135 if m.group()[0] in " \t":
136 cls = find_class(s, m.start())
137 deprecated_methods[name].add((msg, cls, "()"))
138 else:
139 deprecated_funcs[name].add((msg, "", "()"))
140 else:
141 name = m.group(3)
142 m2 = STRING_RE.match(s, m.end())
143 if m2:
144 msg = strip_quotes(m2.group())
145 else:
146 msg = ""
147 msg = " ".join(msg.split())
148 deprecated_classes[name].add((msg, "", ""))
149
150
151def print_deprecated_uses(paths):

Callers 1

mainFunction · 0.85

Calls 11

openFunction · 0.85
strip_quotesFunction · 0.85
find_classFunction · 0.85
walkMethod · 0.80
readMethod · 0.45
joinMethod · 0.45
findallMethod · 0.45
startMethod · 0.45
addMethod · 0.45
matchMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…