titlecase: add package stubs - #16234
Conversation
This comment has been minimized.
This comment has been minimized.
|
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 |
Co-authored-by: Sebastian Rittau <sebastian.rittau@zfutura.de>
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
srittau
left a comment
There was a problem hiding this comment.
Thanks, comments below.
| titlecase.CallbackProtocol | ||
| titlecase.Pattern | ||
| titlecase.tests |
There was a problem hiding this comment.
Please add a short comment why these are on the allowlist for posterity.
|
|
||
| import regex | ||
|
|
||
| Pattern: TypeAlias = re.Pattern[str] | regex.Pattern[str] |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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"] | |||
There was a problem hiding this comment.
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.
| optional-dependencies = ["types-regex"] | |
| dependencies = ["types-regex"] |
Hi, I created it after the comment from
titlecasemaintainer. ppannuto/python-titlecase#100 (comment)I'm guessing this will be preferable for them.