mirror of
https://github.com/evennia/evennia.git
synced 2026-03-16 21:06:30 +01:00
issue #2243 -- prefer f-strings over %-interpolation
edited docs to prefer f-strings, then str.format(), and remove %-interpolation additional ad-hoc documentation fixes, as opportunities seen: - replace Built-In Function (BIF) "min" variable with "mins" - prefer BIF str(var) over "%s" % var - reformat some code examples to clarify multiple args passed to functions - change some single-quote strings to double-quotes for consistency - fix mismatched parens misc edits: - add .vscode/ to gitignore
This commit is contained in:
parent
f45051050e
commit
851ca30be5
30 changed files with 207 additions and 193 deletions
|
|
@ -140,7 +140,7 @@ This is important, in order to know what variables we can use in our callback ou
|
|||
write a single line to be sure our callback is called when we expect it to:
|
||||
|
||||
```python
|
||||
character.msg("You just said {}.".format(message))
|
||||
character.msg(f"You just said {message}.")
|
||||
```
|
||||
|
||||
You can paste this line in-game, then type the `:wq` command to exit the editor and save your
|
||||
|
|
|
|||
|
|
@ -73,8 +73,8 @@ class EditCmd(Command):
|
|||
if obj.typename == "Room":
|
||||
Menu = RoomBuildingMenu
|
||||
else:
|
||||
self.msg("|rThe object {} cannot be
|
||||
edited.|n".format(obj.get_display_name(self.caller)))
|
||||
obj_name = obj.get_display_name(self.caller)
|
||||
self.msg(f"|rThe object {obj_name} cannot be edited.|n")
|
||||
return
|
||||
|
||||
menu = Menu(self.caller, obj)
|
||||
|
|
@ -475,8 +475,7 @@ Excessive spaces will be removed from the left for each line automatically. We
|
|||
information between braces... sometimes using double braces. What might be a bit odd:
|
||||
|
||||
- `{back}` is a direct format argument we'll use (see the `.format` specifiers).
|
||||
- `{{obj...}} refers to the object being edited. We use two braces, because `.format` will remove
|
||||
them.
|
||||
- `{{obj...}}` refers to the object being edited. We use two braces, because `.format` will remove them.
|
||||
|
||||
In `glance`, we also use `{obj.key}` to indicate we want to show the room's key.
|
||||
|
||||
|
|
@ -549,7 +548,7 @@ def glance_exits(room):
|
|||
if room.exits:
|
||||
glance = ""
|
||||
for exit in room.exits:
|
||||
glance += "\n |y{exit}|n".format(exit=exit.key)
|
||||
glance += f"\n |y{exit.key}|n"
|
||||
|
||||
return glance
|
||||
|
||||
|
|
@ -648,7 +647,7 @@ def glance_exits(room):
|
|||
if room.exits:
|
||||
glance = ""
|
||||
for exit in room.exits:
|
||||
glance += "\n |y{exit}|n".format(exit=exit.key)
|
||||
glance += f"\n |y{exit.key}|n"
|
||||
|
||||
return glance
|
||||
|
||||
|
|
@ -662,12 +661,13 @@ def text_exits(caller, room):
|
|||
text += "\n\nExisting exits:"
|
||||
if room.exits:
|
||||
for exit in room.exits:
|
||||
text += "\n |y@e {exit}|n".format(exit=exit.key)
|
||||
text += f"\n |y@e {exit.key}|n"
|
||||
if exit.aliases.all():
|
||||
text += " (|y{aliases}|n)".format(aliases="|n, |y".join(
|
||||
alias for alias in exit.aliases.all()))
|
||||
alias for alias in exit.aliases.all()
|
||||
))
|
||||
if exit.destination:
|
||||
text += " toward {destination}".format(destination=exit.get_display_name(caller))
|
||||
text += f" toward {exit.get_display_name(caller)}"
|
||||
else:
|
||||
text += "\n\n |gNo exit has yet been defined.|n"
|
||||
|
||||
|
|
@ -856,21 +856,19 @@ class RoomBuildingMenu(BuildingMenu):
|
|||
Current title: |c{{obj.key}}|n
|
||||
""".format(back="|n or |y".join(self.keys_go_back)))
|
||||
self.add_choice_edit("description", "d")
|
||||
self.add_choice("exits", "e", glance=glance_exits, text=text_exits,
|
||||
on_nomatch=nomatch_exits)
|
||||
self.add_choice("exits", "e", glance=glance_exits, text=text_exits, on_nomatch=nomatch_exits)
|
||||
|
||||
# Exit sub-menu
|
||||
self.add_choice("exit", "e.*", text=text_single_exit, on_nomatch=nomatch_single_exit)
|
||||
|
||||
|
||||
|
||||
# Menu functions
|
||||
def glance_exits(room):
|
||||
"""Show the room exits."""
|
||||
if room.exits:
|
||||
glance = ""
|
||||
for exit in room.exits:
|
||||
glance += "\n |y{exit}|n".format(exit=exit.key)
|
||||
glance += f"\n |y{exit.key}|n"
|
||||
|
||||
return glance
|
||||
|
||||
|
|
@ -884,12 +882,13 @@ def text_exits(caller, room):
|
|||
text += "\n\nExisting exits:"
|
||||
if room.exits:
|
||||
for exit in room.exits:
|
||||
text += "\n |y@e {exit}|n".format(exit=exit.key)
|
||||
text += f"\n |y@e {exit.key}|n"
|
||||
if exit.aliases.all():
|
||||
text += " (|y{aliases}|n)".format(aliases="|n, |y".join(
|
||||
alias for alias in exit.aliases.all()))
|
||||
alias for alias in exit.aliases.all()
|
||||
))
|
||||
if exit.destination:
|
||||
text += " toward {destination}".format(destination=exit.get_display_name(caller))
|
||||
text += f" toward {exit.get_display_name(caller)}"
|
||||
else:
|
||||
text += "\n\n |gNo exit has yet been defined.|n"
|
||||
|
||||
|
|
@ -905,7 +904,7 @@ def nomatch_exits(menu, caller, room, string):
|
|||
return
|
||||
|
||||
# Open a sub-menu, using nested keys
|
||||
caller.msg("Editing: {}".format(exit.key))
|
||||
caller.msg(f"Editing: {exit.key}")
|
||||
menu.move(exit)
|
||||
return False
|
||||
|
||||
|
|
@ -916,13 +915,13 @@ def text_single_exit(menu, caller):
|
|||
if exit is None:
|
||||
return ""
|
||||
|
||||
return """
|
||||
Exit {exit}:
|
||||
return f"""
|
||||
Exit {exit.key}:
|
||||
|
||||
Enter the exit key to change it, or |y@|n to go back.
|
||||
|
||||
New exit key:
|
||||
""".format(exit=exit.key)
|
||||
"""
|
||||
|
||||
def nomatch_single_exit(menu, caller, room, string):
|
||||
"""The user entered something in the exit sub-menu. Replace the exit key."""
|
||||
|
|
@ -1012,7 +1011,7 @@ def glance_exits(room):
|
|||
if room.exits:
|
||||
glance = ""
|
||||
for exit in room.exits:
|
||||
glance += "\n |y{exit}|n".format(exit=exit.key)
|
||||
glance += f"\n |y{exit.key}|n"
|
||||
|
||||
return glance
|
||||
|
||||
|
|
@ -1026,12 +1025,13 @@ def text_exits(caller, room):
|
|||
text += "\n\nExisting exits:"
|
||||
if room.exits:
|
||||
for exit in room.exits:
|
||||
text += "\n |y@e {exit}|n".format(exit=exit.key)
|
||||
text += f"\n |y@e {exit.key}|n"
|
||||
if exit.aliases.all():
|
||||
text += " (|y{aliases}|n)".format(aliases="|n, |y".join(
|
||||
alias for alias in exit.aliases.all()))
|
||||
alias for alias in exit.aliases.all()
|
||||
))
|
||||
if exit.destination:
|
||||
text += " toward {destination}".format(destination=exit.get_display_name(caller))
|
||||
text += f" toward {exit.get_display_name(caller)}"
|
||||
else:
|
||||
text += "\n\n |gNo exit has yet been defined.|n"
|
||||
|
||||
|
|
@ -1047,7 +1047,7 @@ def nomatch_exits(menu, caller, room, string):
|
|||
return
|
||||
|
||||
# Open a sub-menu, using nested keys
|
||||
caller.msg("Editing: {}".format(exit.key))
|
||||
caller.msg(f"Editing: {exit.key}")
|
||||
menu.open_submenu("commands.building.ExitBuildingMenu", exit, parent_keys=["e"])
|
||||
return False
|
||||
|
||||
|
|
|
|||
|
|
@ -346,7 +346,7 @@ class Room(DefaultRoom):
|
|||
|
||||
def return_appearance(self, looker):
|
||||
# [...]
|
||||
string = "%s\n" % Map(looker).show_map()
|
||||
string = f"{Map(looker).show_map()}\n"
|
||||
# Add all the normal stuff like room description,
|
||||
# contents, exits etc.
|
||||
string += "\n" + super().return_appearance(looker)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue