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

Fix url_path_for typehints #1341

Merged
merged 9 commits into from Nov 30, 2021
Merged

Fix url_path_for typehints #1341

merged 9 commits into from Nov 30, 2021

Conversation

aminalaee
Copy link
Member

@aminalaee aminalaee commented Nov 24, 2021

Changes type hints for url_path_for . There's a mismatch between url_for and url_path_for as one accepts Any and the other one is str. They should both be Any.

Right now url_path_for expects path_parameters to be string, which is not the case, and url_for could be int, UUID, float, etc.

Fixes #1319.

@aminalaee aminalaee changed the title Fix url_for typehints Fix url_path_for typehints Nov 24, 2021
@aminalaee aminalaee requested review from a team and Kludex November 25, 2021 11:06
Copy link
Member

@florimondmanca florimondmanca left a comment

Choose a reason for hiding this comment

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

From reviewing this and the associated issue, this seems legit to me!

starlette/requests.py Outdated Show resolved Hide resolved
@aminalaee
Copy link
Member Author

@PrettyWood @florimondmanca I think the typing.Any isn't worth much for the path_params.

Checking starlette/convertors.py:

CONVERTOR_TYPES = {
    "str": StringConvertor(),
    "path": PathConvertor(),
    "int": IntegerConvertor(),
    "float": FloatConvertor(),
    "uuid": UUIDConvertor(),
}

we could have a Union of these to be more explicit. Any ideas?

setup.cfg Show resolved Hide resolved
@aminalaee aminalaee merged commit 10529a3 into master Nov 30, 2021
@aminalaee aminalaee deleted the fix-request-url-for-type-hint branch November 30, 2021 18:13
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.

Inconsistent Typing Between request.url_for and application.url_path_for
4 participants