Skip to content

refactor: prefer f-strings to .format in docs #13317

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

Merged
merged 1 commit into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/source/cheat_sheet_py3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ See :ref:`async-and-await` for the full detail on typing coroutines and asynchro
# A coroutine is typed like a normal function
async def countdown35(tag: str, count: int) -> str:
while count > 0:
print('T-minus {} ({})'.format(count, tag))
print(f'T-minus {count} ({tag})')
await asyncio.sleep(0.1)
count -= 1
return "Blastoff!"
Expand Down
2 changes: 1 addition & 1 deletion docs/source/final_attrs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ further assignments to final names in type-checked code:

from typing import Final

RATE: Final = 3000
RATE: Final = 3_000

class Base:
DEFAULT_ID: Final = 0
Expand Down
2 changes: 1 addition & 1 deletion docs/source/generics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ non-generic. For example:

class StrDict(dict[str, str]): # This is a non-generic subclass of dict
def __str__(self) -> str:
return 'StrDict({})'.format(super().__str__())
return f'StrDict({super().__str__()})'

data: StrDict[int, int] # Error! StrDict is not generic
data2: StrDict # OK
Expand Down
4 changes: 2 additions & 2 deletions docs/source/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ Arguments with default values can be annotated like so:
.. code-block:: python

def greeting(name: str, excited: bool = False) -> str:
message = 'Hello, {}'.format(name)
message = f'Hello, {name}'
if excited:
message += '!!!'
return message
Expand Down Expand Up @@ -213,7 +213,7 @@ ints or strings, but no other types. You can express this using the :py:data:`~t

def normalize_id(user_id: Union[int, str]) -> str:
if isinstance(user_id, int):
return 'user-{}'.format(100000 + user_id)
return f'user-{100_000 + user_id}'
else:
return user_id

Expand Down
4 changes: 2 additions & 2 deletions docs/source/kinds_of_types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ but it's not obvious from its signature:

def greeting(name: str) -> str:
if name:
return 'Hello, {}'.format(name)
return f'Hello, {name}'
else:
return 'Hello, stranger'

Expand All @@ -469,7 +469,7 @@ enabled:

def greeting(name: Optional[str]) -> str:
if name:
return 'Hello, {}'.format(name)
return f'Hello, {name}'
else:
return 'Hello, stranger'

Expand Down
2 changes: 1 addition & 1 deletion docs/source/literal_types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ Let's start with a definition:

def assert_never(value: NoReturn) -> NoReturn:
# This also works in runtime as well:
assert False, 'This code should never be reached, got: {0}'.format(value)
assert False, f'This code should never be reached, got: {value}'

class Direction(Enum):
up = 'up'
Expand Down
10 changes: 5 additions & 5 deletions docs/source/more_types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ expect to get back when ``await``-ing the coroutine.
import asyncio

async def format_string(tag: str, count: int) -> str:
return 'T-minus {} ({})'.format(count, tag)
return f'T-minus {count} ({tag})'

async def countdown_1(tag: str, count: int) -> str:
while count > 0:
Expand Down Expand Up @@ -882,7 +882,7 @@ You may also choose to create a subclass of :py:class:`~typing.Awaitable` instea

def __await__(self) -> Generator[Any, None, str]:
for i in range(n, 0, -1):
print('T-minus {} ({})'.format(i, tag))
print(f'T-minus {i} ({tag})')
yield from asyncio.sleep(0.1)
return "Blastoff!"

Expand Down Expand Up @@ -919,7 +919,7 @@ To create an iterable coroutine, subclass :py:class:`~typing.AsyncIterator`:

async def countdown_4(tag: str, n: int) -> str:
async for i in arange(n, 0, -1):
print('T-minus {} ({})'.format(i, tag))
print(f'T-minus {i} ({tag})')
await asyncio.sleep(0.1)
return "Blastoff!"

Expand All @@ -941,7 +941,7 @@ generator type as the return type:
@asyncio.coroutine
def countdown_2(tag: str, count: int) -> Generator[Any, None, str]:
while count > 0:
print('T-minus {} ({})'.format(count, tag))
print(f'T-minus {count} ({tag})')
yield from asyncio.sleep(0.1)
count -= 1
return "Blastoff!"
Expand Down Expand Up @@ -1045,7 +1045,7 @@ a subtype of (that is, compatible with) ``Mapping[str, object]``, since

def print_typed_dict(obj: Mapping[str, object]) -> None:
for key, value in obj.items():
print('{}: {}'.format(key, value))
print(f'{key}: {value}')

print_typed_dict(Movie(name='Toy Story', year=1995)) # OK

Expand Down
2 changes: 1 addition & 1 deletion docs/source/mypy_daemon.rst
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ In this example, the function ``format_id()`` has no annotation:
.. code-block:: python

def format_id(user):
return "User: {}".format(user)
return f"User: {user}"

root = format_id(0)

Expand Down