-
First Check
Commit to Help
Example Code# fastapi/docs_src/python_types/tutorial003.py
def get_name_with_age(name: str, age: int):
name_with_age = name + " is this old: " + age
return name_with_ageDescriptionI am currently doing some research on the security of Python type. I sincerely hope that I can help Fastapi become stronger and safer Operating SystemLinux Operating System DetailsNo response FastAPI Version0.85.0 Python Version3.10.6 Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments
-
|
@PVMPATCH : it's not related to FastAPI, but to Python in general. You can find more information on : https://stackoverflow.com/questions/62201680/why-cant-python-concatenate-a-string-and-int The Zen of Python say : |
Beta Was this translation helpful? Give feedback.
-
I mean this code can not run successfully in Python 3.10.6. https://github.com/tiangolo/fastapi/blob/master/docs_src/python_types/tutorial003.py |
Beta Was this translation helpful? Give feedback.
-
|
@PVMPATCH : ok, i understand. In fact, this code does not work, but it is to show this problem that it was written. You can see the documentation page where this code is posted to better understand: |
Beta Was this translation helpful? Give feedback.
-
|
It's just an example used by documentation (precisely what @axel584 linked). Context is important 😄 |
Beta Was this translation helpful? Give feedback.
-
|
maybe you can just create a PR to fix it |
Beta Was this translation helpful? Give feedback.
-
|
@PVMPATCH Python doesn't support adding strings and integers directly. It would raise an error. You have to cast it first. It's a feature of the language. Please read that whole section of the documentation you linked. It's explaining how Python works, and how type annotations and tools can help you detect bugs in your code like that one and fix it. |
Beta Was this translation helpful? Give feedback.
-
|
Assuming the original need was handled, this will be automatically closed now. But feel free to add more comments or create new issues or PRs. |
Beta Was this translation helpful? Give feedback.
-
|
Assuming the original need was handled, this will be automatically closed now. But feel free to add more comments or create new issues or PRs. |
Beta Was this translation helpful? Give feedback.

@PVMPATCH : it's not related to FastAPI, but to Python in general. You can find more information on : https://stackoverflow.com/questions/62201680/why-cant-python-concatenate-a-string-and-int
The Zen of Python say :
Explicit is better than implicit.https://peps.python.org/pep-0020/