Fix the check for undocumented library calls
Your task
An AI wrote a script that calls requests.get_json(url). That method does not exist in the requests library, and nobody noticed until the script ran. Your team now checks every library call in AI code against the list of methods in the library's documentation.
An assistant wrote unverified_api_calls(known_methods, calls). It is in the editor. It has a bug. Find it and fix it.
Input and output:
known_methods: the documented method names, such asrequests.get. It can contain repeats.calls: the method names the code calls, in order. It can contain repeats.- Return the calls that are not documented, in the order they first appear in
calls, each once.
Rules the tests check:
- A call is documented only when
known_methodscontains exactly the same string: same case, same spaces, same everything. - Report each undocumented call once, at the position where it first appears.
- A documented call never appears in the result.
Examples
unverified_api_calls(known_methods: list[str], calls: list[str]) -> list[str]Example 1
Input
unverified_api_calls(["requests.get", "requests.post", "Response.json"], ["requests.get", "requests.get_json"])Output
["requests.get_json"]Example 2
Input
unverified_api_calls(["requests.get", "Response.json"], ["requests.get"])Output
[]