gh-125633: Add function ispackage to stdlib inspect (#125634)

---------

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
This commit is contained in:
Zhikang Yan 2024-10-27 12:57:43 +08:00 committed by GitHub
parent c51b56038b
commit dad3453129
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 37 additions and 6 deletions

View file

@ -6,9 +6,9 @@
Here are some of the useful functions provided by this module:
ismodule(), isclass(), ismethod(), isfunction(), isgeneratorfunction(),
isgenerator(), istraceback(), isframe(), iscode(), isbuiltin(),
isroutine() - check object types
ismodule(), isclass(), ismethod(), ispackage(), isfunction(),
isgeneratorfunction(), isgenerator(), istraceback(), isframe(),
iscode(), isbuiltin(), isroutine() - check object types
getmembers() - get members of an object that satisfy a given condition
getfile(), getsourcefile(), getsource() - find an object's source code
@ -128,6 +128,7 @@
"ismethoddescriptor",
"ismethodwrapper",
"ismodule",
"ispackage",
"isroutine",
"istraceback",
"markcoroutinefunction",
@ -186,6 +187,10 @@ def ismethod(object):
"""Return true if the object is an instance method."""
return isinstance(object, types.MethodType)
def ispackage(object):
"""Return true if the object is a package."""
return ismodule(object) and hasattr(object, "__path__")
def ismethoddescriptor(object):
"""Return true if the object is a method descriptor.