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 ourterms of serviceand privacy statement.We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raw docstring (leadingr) defeats form feed\ftruncation #10998

Open
9 tasks done
Kludexopened this issue Jan 21, 2024 Discussed in #10531 · 3 comments
Open
9 tasks done

Raw docstring (leadingr) defeats form feed\ftruncation #10998

Kludexopened this issue Jan 21, 2024 Discussed in #10531 · 3 comments
Labels
bug Something isn't working

Comments

@Kludex
Copy link
Member

Kludex commented Jan 21, 2024

Discussed in#10531

Originally posted byjamesbrazaOctober 26, 2023

First Check

  • I added a very descriptive title here.
  • I used the GitHub search to find a similar question and didn't find it.
  • I searched the FastAPI documentation, with the integrated search.
  • I already searched in Google "How to X in FastAPI" and didn't find any information.
  • I already read and followed all the tutorial in the docs and didn't find an answer.
  • I already checked if it is not related to FastAPI but toPydantic.
  • I already checked if it is not related to FastAPI but toSwagger UI.
  • I already checked if it is not related to FastAPI but toReDoc.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

fromfastapiimportFastAPI

app=FastAPI()


@app.post("/lof")
deffoo(arg:int=5)->int:
"""
Some function.

\f

Args:
arg: Some argument

Returns:
Some integer.
"""
returnarg

Description

Runningruff==0.1.3on this,D301will autofix to make the docstring be a raw string (lead byr).

@app.post("/lof")
deffoo(arg:int=5)->int:
r "" "
Some function.

\f

Args:
arg: Some argument

Returns:
Some integer.
"""
returnarg

However, this breaks the form feed\ftruncation from working, perhttps://fastapi.tiangolo /advanced/path-operation-advanced-configuration/#advanced-description-from-docstring

I think form feed\ftruncation should still work even if the docstring is a raw string.

Operating System

macOS

Operating System Details

n/a

FastAPI Version

0.104.0

Pydantic Version

2.4.2

Python Version

3.11.5

Additional Context

No response

@Kludex Kludex added question Question or problem bug Something isn't working and removed question Question or problem labels Jan 21, 2024
@KaniKim
Copy link
Contributor

KaniKim commented Jan 22, 2024

I little bit handled this by adding some code.
I don't know what you actually want, but you want like this code situation?

fast

Above code is with raw string that print to normal string.
And also here is my code changed version.

fastapi-code

Here is code about I write

carbon

@dolfinus
Copy link
Contributor

Well,r "\f"=="\\f"!="\f"

With change you propose to docstrings likeThis endpoint saves data to C:\files\datawill be truncated toThis endpoint saves data to C:

@ShreySinha02
Copy link

ShreySinha02 commented Feb 15, 2024

opened the#11149pr
used codecs to convert rawstring so that it can be split on \f

self.description=codecs.decode(self.description,"unicode_escape")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants