Replace AnyStr with str | bytes union type#464
Closed
kimjune01 wants to merge 1 commit intopallets:mainfrom
Closed
Replace AnyStr with str | bytes union type#464kimjune01 wants to merge 1 commit intopallets:mainfrom
kimjune01 wants to merge 1 commit intopallets:mainfrom
Conversation
AnyStr is deprecated in Python 3.13 and was being used incorrectly throughout the codebase. According to Python typing documentation, AnyStr should only be used as a TypeVar constraint for generic functions, not for parameters that accept either str or bytes. This commit replaces all AnyStr usage with the explicit str | bytes union type, which is the correct way to annotate parameters that can accept either type. Changes: - Remove AnyStr imports from all affected modules - Replace AnyStr type hints with str | bytes in: - Function parameters (data, send, receive) - Protocol method signatures - Signal handler type comments Fixes pallets#451
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #451.
`AnyStr` constrains a function to use either `str` or `bytes` consistently
across all parameters and return type. Several Quart APIs accept both
independently — `AnyStr` was incorrectly restricting callers.
Replace with explicit `str | bytes` union where the constraint isn't needed.
Prior work: #452 addressed the same issue but has been inactive for 6 months.