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

implement missing str methods #377

Merged
merged 2 commits into from
Jun 2, 2023
Merged

implement missing str methods #377

merged 2 commits into from
Jun 2, 2023

Conversation

davidism
Copy link
Member

@davidism davidism commented Jun 2, 2023

format_map was missing, meaning the format arguments would not be escaped when using it. casefold, removeprefix, and removesuffix were missing, meaning they'd return str instead of Markup. The remove... methods are only in Python >= 3.9.

fixes #370

casefold, removeprefix, removesuffix
@davidism davidism added this to the 2.1.3 milestone Jun 2, 2023
@davidism davidism merged commit f3c78b1 into 2.1.x Jun 2, 2023
12 checks passed
@davidism davidism deleted the str-methods branch June 2, 2023 18:05
@@ -208,6 +214,10 @@ def format(self, *args: t.Any, **kwargs: t.Any) -> "Markup":
formatter = EscapeFormatter(self.escape)
return self.__class__(formatter.vformat(self, args, kwargs))

def format_map(self, map: t.Mapping[str, t.Any]) -> str: # type: ignore[override]
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this return Markup? Although technically it would be even more correct to return typing_extensions.Self, since you're using self.__class__, but that's a refactor you would have to apply pretty much everywhere.

Copy link
Member Author

Choose a reason for hiding this comment

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

See #379

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants