mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Check the number of arguments passed to `safe_getattr()
` (#12961)
This commit is contained in:
parent
c3088ef1df
commit
883faaa568
@ -389,6 +389,10 @@ def isgenericalias(obj: Any) -> TypeIs[types.GenericAlias]:
|
||||
|
||||
def safe_getattr(obj: Any, name: str, *defargs: Any) -> Any:
|
||||
"""A getattr() that turns all exceptions into AttributeErrors."""
|
||||
if len(defargs) > 1:
|
||||
msg = f'safe_getattr expected at most 3 arguments, got {len(defargs)}'
|
||||
raise TypeError(msg)
|
||||
|
||||
try:
|
||||
return getattr(obj, name, *defargs)
|
||||
except Exception as exc:
|
||||
|
Loading…
Reference in New Issue
Block a user