Skip to content

titlecase: add package stubs - #16234

Open
Vulwsztyn wants to merge 3 commits into
python:mainfrom
Vulwsztyn:titlecase
Open

titlecase: add package stubs#16234
Vulwsztyn wants to merge 3 commits into
python:mainfrom
Vulwsztyn:titlecase

Conversation

@Vulwsztyn

@Vulwsztyn Vulwsztyn commented Aug 18, 2026

Copy link
Copy Markdown

Hi, I created it after the comment from titlecase maintainer. ppannuto/python-titlecase#100 (comment)

I'm guessing this will be preferable for them.

> uv run tests/runtests.py stubs/titlecase --run-stubtest
...
--- success, 1 file checked ---

Running stubtest...
titlecase... (18.43 s) success
Note: titlecase is not currently tested on darwin in typeshed's CI

Regression tests: No test_cases folder for 'titlecase'!


--- TEST SUMMARY: All tests passed! ---

pre-commit Success
Check structure: Success
Pyright: Success
ty: Success
pyrefly: Success
mypy: Success
stubtest: Success
Pyright regression tests: Success
mypy regression test: Success

@github-actions

This comment has been minimized.

@Vulwsztyn

Copy link
Copy Markdown
Author

Might I ask for assistance resolving the CI error?

At the same time I'd like to ask if the approach I've taken regarding the conditional import as union is ok.

Actual implementation: https://github.com/ppannuto/python-titlecase/blob/42f43e2de55bf003b286c6f8e8d8b2d26676a167/titlecase/__init__.py#L17

Comment thread stubs/titlecase/METADATA.toml Outdated
Vulwsztyn and others added 2 commits August 19, 2026 14:56
Co-authored-by: Sebastian Rittau <sebastian.rittau@zfutura.de>
@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@srittau srittau left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks, comments below.

Comment on lines +1 to +3
titlecase.CallbackProtocol
titlecase.Pattern
titlecase.tests

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please add a short comment why these are on the allowlist for posterity.


import regex

Pattern: TypeAlias = re.Pattern[str] | regex.Pattern[str]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We prefix type-only symbols in typeshed, i.e. _Pattern in this case. (This should also make the stubtest allowlist entry redundant.)

APOS_SECOND: Final[Pattern]
UC_INITIALS: Final[Pattern]

class CallbackProtocol(Protocol):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Same here. Also this should be annotated with @type_check_only (from typing):

@type_check_only
class _CallbackProtocol(Protocol):

@@ -0,0 +1,3 @@
version = "2.4.*"
upstream-repository = "https://github.com/ppannuto/python-titlecase"
optional-dependencies = ["types-regex"]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Considering that we need to unconditionally import regex in the stubs (and I'm not sure that we can work around this), this should be a regular dependency. While this is not optimal, it only pulls in a type package, so it's not the end of the world.

Suggested change
optional-dependencies = ["types-regex"]
dependencies = ["types-regex"]

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