Skip to content

Add py.typed marker to cosmology - #20568

Merged
nstarman merged 1 commit into
astropy:mainfrom
gitpsii:add-cosmology-pytyped
Oct 9, 2026
Merged

nstarman merged 1 commit into
astropy:mainfrom
gitpsii:add-cosmology-pytyped

Conversation

@gitpsii

@gitpsii gitpsii commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Description

This pull request adds the py.typed marker file to astropy.cosmology, marking the subpackage as typed for static type checkers.

Fixes #20555

AI Disclosure

"N/A".

  • I certify that I am human and that I take full responsibility for this pull request including all interactions with reviewers.

Merge method

  • By checking this box, the PR author has requested that maintainers do NOT use the "Squash and Merge" button. Maintainers should respect this when possible; however, the final decision is at the discretion of the maintainer that merges the PR.

@gitpsii
gitpsii requested a review from a team as a code owner October 8, 2026 17:22
@gitpsii
gitpsii requested a review from nstarman October 8, 2026 17:22
@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.

  • Do the proposed changes actually accomplish desired goals?
  • Do the proposed changes follow the Astropy coding guidelines?
  • Are tests added/updated as required? If so, do they follow the Astropy testing guidelines?
  • Are docs added/updated as required? If so, do they follow the Astropy documentation guidelines?
  • Is rebase and/or squash necessary? If so, please provide the author with appropriate instructions. Also see instructions for rebase and squash.
  • Did the CI pass? If no, are the failures related? If you need to run daily and weekly cron jobs as part of the PR, please apply the "Extra CI" label. Codestyle issues can be fixed by the bot.
  • Is a change log needed? If yes, did the change log check pass? If no, add the "no-changelog-entry-needed" label. If this is a manual backport, use the "skip-changelog-checks" label unless special changelog handling is necessary.
  • Is this a big PR that makes a "What's new?" entry worthwhile and if so, is (1) a "what's new" entry included in this PR and (2) the "whatsnew-needed" label applied?
  • At the time of adding the milestone, if the milestone set requires a backport to release branch(es), apply the appropriate "backport-X.Y.x" label(s) before merge.

@pllim pllim added this to the v8.1.0 milestone Oct 8, 2026
@pllim pllim added the typing related to type annotations label Oct 8, 2026
@astrofrog

Copy link
Copy Markdown
Member

Just a note that we should double check that this actually works - I thought it could only be defined at a package level

@nstarman

nstarman commented Oct 8, 2026

Copy link
Copy Markdown
Member

I agree this should be tested. https://peps.python.org/pep-0561/#packaging-type-information indicates that the PEP says it should work. But IDK what mypy does.

@gitpsii

gitpsii commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor Author

Verified that astropy/cosmology/py.typed is included in the source distribution. I also built a minimal test package with a subpackage-level marker and confirmed that demo/cosmology/py.typed was included in its wheel.

Tested mypy against the installed test package, but it inferred the same types after I removed the marker, so this test did not establish whether mypy's behavior depended on py.typed.

I haven't verified whether Astropy's actual wheel includes the marker. My local wheel build failed because the required Microsoft Visual C++ build tools were unavailable.

Is there a preferred test for verifying that mypy recognizes a py.typed marker placed inside a regular subpackage, such as astropy/cosmology/py.typed?

@pllim

pllim commented Oct 9, 2026

Copy link
Copy Markdown
Member

@gitpsii do you use WSL2? You might be able to grab C lib stuff off conda that way, but it has been a while since I used it, so I am not 100% sure.

@gitpsii

gitpsii commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the suggestion! I currently don't have enough disk space to set up WSL2 and build Astropy in a Linux environment.

I verified that astropy/cosmology/py.typed is included in the source distribution. I also built a minimal test package with a subpackage-level marker and confirmed that demo/cosmology/py.typed was included in its wheel.

Would it be possible to verify the marker's inclusion in Astropy's wheel through an existing CI job, or is there a lighter-weight test you would recommend?

@nstarman nstarman 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.

Given the PEP saying static type analyzers should support this and that it will be a long time (if ever) that Astropy ships this at the top level, I think this PR is worth it, even if mypy doesn't pick up on it.

@github-project-automation github-project-automation Bot moved this from Triage to Reviewer approved in Cosmology, the Expansion Oct 9, 2026
@Cadair

Cadair commented Oct 9, 2026

Copy link
Copy Markdown
Member

On the topic of checking the wheels: we should configure our test Linux wheel job to upload the artifact to actions so people can download it and check in situations like this.

@nstarman

nstarman commented Oct 9, 2026

Copy link
Copy Markdown
Member

@Cadair, a good idea! I opened an issue based on that comment. Feel free to edit it :)

@nstarman

nstarman commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

Thanks @gitpsii!
I'd rather have this than not, even if it might be a no-op :)

@nstarman
nstarman merged commit 3372056 into astropy:main Oct 9, 2026
51 of 54 checks passed
@github-project-automation github-project-automation Bot moved this from Reviewer approved to Done in Cosmology, the Expansion Oct 9, 2026
@gitpsii

gitpsii commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review and for opening the follow-up issue! I appreciate the guidance. I'm glad this also highlighted a way to make wheel inspection easier for future contributors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Add py.typed to astropy/cosmology

5 participants