MCPcopy Create free account
hub / github.com/ModalityDance/Omni-R1 / check_docstrings

Function check_docstrings

src/transformers/utils/check_docstrings.py:948–1038  ·  view source on GitHub ↗

Check docstrings of all public objects that are callables and are documented. By default, only checks the diff. Args: overwrite (`bool`, *optional*, defaults to `False`): Whether to fix inconsistencies or not. check_all (`bool`, *optional*, defaults to `False`):

(overwrite: bool = False, check_all: bool = False)

Source from the content-addressed store, hash-verified

946
947
948def check_docstrings(overwrite: bool = False, check_all: bool = False):
949 """
950 Check docstrings of all public objects that are callables and are documented. By default, only checks the diff.
951
952 Args:
953 overwrite (`bool`, *optional*, defaults to `False`):
954 Whether to fix inconsistencies or not.
955 check_all (`bool`, *optional*, defaults to `False`):
956 Whether to check all files.
957 """
958 module_diff_files = None
959 if not check_all:
960 module_diff_files = set()
961 repo = Repo(PATH_TO_REPO)
962 # Diff from index to unstaged files
963 for modified_file_diff in repo.index.diff(None):
964 if modified_file_diff.a_path.startswith("src/transformers"):
965 module_diff_files.add(modified_file_diff.a_path)
966 # Diff from index to `main`
967 for modified_file_diff in repo.index.diff(repo.refs.main.commit):
968 if modified_file_diff.a_path.startswith("src/transformers"):
969 module_diff_files.add(modified_file_diff.a_path)
970 # quick escape route: if there are no module files in the diff, skip this check
971 if len(module_diff_files) == 0:
972 return
973 print(" Checking docstrings in the following files:" + "\n - " + "\n - ".join(module_diff_files))
974
975 failures = []
976 hard_failures = []
977 to_clean = []
978 for name in dir(transformers):
979 # Skip objects that are private or not documented.
980 if name.startswith("_") or ignore_undocumented(name) or name in OBJECTS_TO_IGNORE:
981 continue
982
983 obj = getattr(transformers, name)
984 if not callable(obj) or not isinstance(obj, type) or getattr(obj, "__doc__", None) is None:
985 continue
986
987 # If we are checking against the diff, we skip objects that are not part of the diff.
988 if module_diff_files is not None:
989 object_file = find_source_file(getattr(transformers, name))
990 object_file_relative_path = "src/" + str(object_file).split("/src/")[1]
991 if object_file_relative_path not in module_diff_files:
992 continue
993
994 # Check docstring
995 try:
996 result = match_docstring_with_signature(obj)
997 if result is not None:
998 old_doc, new_doc = result
999 else:
1000 old_doc, new_doc = None, None
1001 except Exception as e:
1002 print(e)
1003 hard_failures.append(name)
1004 continue
1005 if old_doc != new_doc:

Callers 1

Calls 7

ignore_undocumentedFunction · 0.90
find_source_fileFunction · 0.85
fix_docstringFunction · 0.85
splitMethod · 0.80
diffMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected