Skip to content

Conversation

@aminalaee
Copy link
Contributor

@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
Contributor

@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!

@aminalaee
Copy link
Contributor 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?

@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

5 participants