Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Type Annotations and Improve Stub Structure for pyrage-stubs #83

Merged
merged 1 commit into from
Oct 1, 2024
Merged

Fix Type Annotations and Improve Stub Structure for pyrage-stubs #83

merged 1 commit into from
Oct 1, 2024

Conversation

Alchemyst0x
Copy link
Contributor

Description:

This PR addresses several issues related to the type annotations and structure of the pyrage-stubs package. The following changes were made:

  1. Renamed pyrage-stubs/pyrage-stubs to pyrage-stubs/pyrage:

    • The pyrage-stubs folder was renamed to pyrage inside the pyrage-stubs directory to better align with the expected structure for a stubs-only package.
    • This change ensures that the stubs mirror the actual package structure and are correctly recognized by type checkers.
  2. Prefixed _Identity and _Recipient as Internal Types:

    • The Identity and Recipient types were prefixed with an underscore (_Identity, _Recipient) to indicate that they are internal and not part of the public API.
    • These types are now excluded from __all__, ensuring they are not exposed when users import the package.
  3. Ensured py.typed is Present:

    • A py.typed file was added to the pyrage directory to signal to type checkers that the package is fully typed.
  4. Corrected encrypt_io params:

    • Added previously missing out_io param to this function.

Why These Changes Were Made:

  • The previous structure (pyrage-stubs/pyrage-stubs) was causing issues with type checkers not recognizing the stubs correctly. Renaming the folder to pyrage resolves this.
  • The _Identity and _Recipient types were exposed in the public API, which could lead to confusion. By prefixing them with an underscore and excluding them from __all__, we ensure they are used internally only.
  • The py.typed file is necessary for type checkers like mypy and Pyright to recognize the package as typed.

Testing:

  • The changes were tested locally, and the type annotations are now correctly recognized by type checkers (e.g., Pyright in VSCode).
  • All unit tests pass successfully.

Notes:

  • The renaming of the pyrage-stubs folder to pyrage inside the pyrage-stubs directory is the only structural change that might need further discussion. This was done to align with the expected structure for stubs-only packages.

Issue Reference:

@woodruffw
Copy link
Owner

  • A py.typed file was added to the pyrage directory to signal to type checkers that the package is fully typed.

I think this shouldn't be necessary, per PEP 561: the -stubs prefix always indicates typing information:

Note that for stub-only packages adding a py.typed marker is not needed since the name *-stubs is enough to indicate it is a source of typing information.

Copy link
Owner

@woodruffw woodruffw left a comment

Choose a reason for hiding this comment

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

Thanks, looks good to me. I'm now somewhat mystified as to how I got the types working locally the last time I used my own library, but this seems strictly more correct than whatever I was doing 🙂

@woodruffw woodruffw merged commit 125b12b into woodruffw:main Oct 1, 2024
17 checks passed
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.

2 participants