WebSafe 3.7github.com
|
|
🏠
Skip to content

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

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

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

Conversation

@Xiaokang2022
Copy link
Contributor

@Xiaokang2022 Xiaokang2022 commented Oct 17, 2024

Copy link
Contributor

@nineteendo nineteendo left a comment

Choose a reason for hiding this comment

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

Can you add tests and fix the sphinx markup?

@Wulian233
Copy link
Contributor

Please add a unittest and document.

Also add to 3.14 what's new(recommend)

@tomasr8
Copy link
Member

tomasr8 commented Oct 17, 2024

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 Xiaokang2022 changed the title gh-125633: Adding function ispackage to stdlib inspect gh-125633: Add function ispackage to stdlib inspect Oct 17, 2024
@Wulian233
Copy link
Contributor

LGTM

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

LGTM.

Copy link
Member

@Eclips4 Eclips4 left a comment

Choose a reason for hiding this comment

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

Thanks!

@vstinner
Copy link
Member

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

Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

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

Thanks! Several comments :)

@erlend-aasland erlend-aasland removed their request for review October 21, 2024 10:08
@ncoghlan
Copy link
Contributor

ncoghlan commented Oct 27, 2024

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 ncoghlan merged commit dad3453 into python:main Oct 27, 2024
@ncoghlan
Copy link
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
Contributor

Choose a reason for hiding this comment

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

This last test genuinely made me laugh :)

@Xiaokang2022 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

8 participants

Comments