FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-125633: Add function `ispackage` to stdlib `inspect` by Xiaokang2022 · Pull Request #125634 · python/cpython · GitHub

/ cpython Public

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

Merged
ncoghlan merged 14 commits into
python:mainfrom
Xiaokang2022:add-ispackage
Oct 27, 2024
Merged

gh-125633: Add function ispackage to stdlib inspect#125634
ncoghlan merged 14 commits into
python:mainfrom
Xiaokang2022:add-ispackage

Conversation

Xiaokang2022 commented Oct 17, 2024
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Contributor

nineteendo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Can you add tests and fix the sphinx markup?

Copy link
Copy Markdown
Contributor

Please add a unittest and document.

Also add to 3.14 what's new(recommend)

tomasr8 commented Oct 17, 2024

Copy link
Copy Markdown
Member

One of the tests is currently failing because you also need to add the new test folder to the Makefile:

test/test_inspect \

should be:

  test/test_inspect \
+ test/test_inspect/inspect_simple_pkg \

Xiaokang2022 changed the title gh-125633: Adding function ispackage to stdlib inspect gh-125633: Add function ispackage to stdlib inspect Oct 17, 2024

Copy link
Copy Markdown
Contributor

LGTM

vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM.

Comment thread Doc/library/inspect.rst
Comment thread Doc/library/inspect.rst Outdated
Comment thread Doc/whatsnew/3.14.rst Outdated
Comment thread Lib/inspect.py Outdated

Eclips4 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thanks!

Copy link
Copy Markdown
Member

@brettcannon @ncoghlan: Is it the correct way to check if a module a package, ismodule(object) and hasattr(object, "__path__")?

sobolevn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thanks! Several comments :)

Comment thread Lib/test/test_inspect/test_inspect.py Outdated
Comment thread Makefile.pre.in Outdated
Comment thread Lib/test/test_inspect/test_inspect.py Outdated
erlend-aasland removed their request for review October 21, 2024 10:08

ncoghlan commented Oct 27, 2024
edited
Loading

Copy link
Copy Markdown
Contributor

I'm not sure __path__ is mandatory anymore, as I believe it's just a way to override __spec__. I'll double check the importlib code.

Edit: after checking the importlib code, I'm happy simply looking for __path__ is still the right check for runtime introspection. importlib itself handles merging __path__, __spec__.is_package and __spec__.submodule_search_locations into a single final __path__ list when it creates the import package module instances.

This also keeps things consistent with the glossary's definition of a package as a module with a __path__ attribute.

ncoghlan merged commit dad3453 into python:main Oct 27, 2024

Copy link
Copy Markdown
Contributor

Thanks for the PR @Xiaokang2022, and thanks for the prior reviews all!

self.istest(inspect.ispackage, 'importlib')
self.assertFalse(inspect.ispackage(inspect))
self.assertFalse(inspect.ispackage(mod))
self.assertFalse(inspect.ispackage(':)'))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This last test genuinely made me laugh :)

Xiaokang2022 deleted the add-ispackage branch January 6, 2025 04:40
ebonnal pushed a commit to ebonnal/cpython that referenced this pull request Jan 12, 2025
…#125634)

---------

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants


Back | FazBrowse Home | New Git URL