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

Pyright reports private import usage #4

Open
richtea opened this issue Nov 21, 2024 · 1 comment · May be fixed by #5
Open

Pyright reports private import usage #4

richtea opened this issue Nov 21, 2024 · 1 comment · May be fixed by #5

Comments

@richtea
Copy link

richtea commented Nov 21, 2024

First of all, thanks for casefy!

I'm having a minor issue with linting that is caused by the import mechanism that casefy uses. Specifically, if we use casefy as documented, the Pyright type checker reports that we are using a private import:

import casefy
PascalCase = casefy.pascalcase  # <- this line triggers a reportPrivateImportUsage error

The reason is that, although __init__.py imports the symbols e.g. pascalcase, they are considered private according to type checker rules unless they are re-exported via the __all__ mechanism.

The workarounds are:

  1. Suppress the type checker error.
  2. Import the casefy module directly i.e. from casefy import casefy. This makes the symbols externally visible.

The fix is to re-export all the symbols in __init__.py as follows:

# __init__.py
__version__ = "0.1.7"

from .casefy import (
    camelcase,
    pascalcase,
    snakecase,
    constcase,
    kebabcase,
    upperkebabcase,
    separatorcase,
    sentencecase,
    titlecase,
    alphanumcase,
    lowercase,
    uppercase,
    capitalcase
)

# Don't expose the submodule itself
del globals()["casefy"]

__all__ = [
    "camelcase",
    "pascalcase",
    "snakecase",
    "constcase",
    "kebabcase",
    "upperkebabcase",
    "separatorcase",
    "sentencecase",
    "titlecase",
    "alphanumcase",
    "lowercase",
    "uppercase",
    "capitalcase"
]

I'm happy to create a PR if you like.

@dmlls
Copy link
Owner

dmlls commented Nov 22, 2024

Hi @richtea, thanks for the heads-up!

I'll be happy to accept a PR as well :)

@richtea richtea linked a pull request Nov 24, 2024 that will close this issue
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 a pull request may close this issue.

2 participants