Ran black on sources

This commit is contained in:
Griatch 2024-04-27 22:26:18 +02:00
parent 49330826f3
commit fd39935d19
9 changed files with 56 additions and 29 deletions

View file

@ -638,8 +638,8 @@ class CmdOption(COMMAND_DEFAULT_CLASS):
flags[new_name] = new_val flags[new_name] = new_val
# If we're manually assign a display size, turn off auto-resizing # If we're manually assign a display size, turn off auto-resizing
if new_name in ['SCREENWIDTH', 'SCREENHEIGHT']: if new_name in ["SCREENWIDTH", "SCREENHEIGHT"]:
flags['AUTORESIZE'] = False flags["AUTORESIZE"] = False
self.msg( self.msg(
f"Option |w{new_name}|n was changed from '|w{old_val}|n' to" f"Option |w{new_name}|n was changed from '|w{old_val}|n' to"

View file

@ -5,13 +5,13 @@ Building and world design commands
import re import re
import typing import typing
import evennia
from django.conf import settings from django.conf import settings
from django.core.paginator import Paginator from django.core.paginator import Paginator
from django.db.models import Max, Min, Q from django.db.models import Max, Min, Q
import evennia
from evennia import InterruptCommand from evennia import InterruptCommand
from evennia.commands.cmdhandler import (generate_cmdset_providers, from evennia.commands.cmdhandler import generate_cmdset_providers, get_and_merge_cmdsets
get_and_merge_cmdsets)
from evennia.locks.lockhandler import LockException from evennia.locks.lockhandler import LockException
from evennia.objects.models import ObjectDB from evennia.objects.models import ObjectDB
from evennia.prototypes import menus as olc_menus from evennia.prototypes import menus as olc_menus
@ -24,10 +24,18 @@ from evennia.utils.dbserialize import deserialize
from evennia.utils.eveditor import EvEditor from evennia.utils.eveditor import EvEditor
from evennia.utils.evmore import EvMore from evennia.utils.evmore import EvMore
from evennia.utils.evtable import EvTable from evennia.utils.evtable import EvTable
from evennia.utils.utils import (class_from_module, crop, dbref, display_len, from evennia.utils.utils import (
format_grid, get_all_typeclasses, class_from_module,
inherits_from, interactive, list_to_string, crop,
variable_from_module) dbref,
display_len,
format_grid,
get_all_typeclasses,
inherits_from,
interactive,
list_to_string,
variable_from_module,
)
COMMAND_DEFAULT_CLASS = class_from_module(settings.COMMAND_DEFAULT_CLASS) COMMAND_DEFAULT_CLASS = class_from_module(settings.COMMAND_DEFAULT_CLASS)
@ -170,7 +178,7 @@ class ObjManipCommand(COMMAND_DEFAULT_CLASS):
def get_object_typeclass( def get_object_typeclass(
self, obj_type: str = "object", typeclass: str = None, method: str = "cmd_create", **kwargs self, obj_type: str = "object", typeclass: str = None, method: str = "cmd_create", **kwargs
) -> tuple[typing.Optional['Typeclass'], list[str]]: ) -> tuple[typing.Optional["Typeclass"], list[str]]:
""" """
This hook is called by build commands to determine which typeclass to use for a specific This hook is called by build commands to determine which typeclass to use for a specific
purpose. purpose.

View file

@ -9,6 +9,7 @@ Communication commands:
from django.conf import settings from django.conf import settings
from django.db.models import Q from django.db.models import Q
from evennia.accounts import bots from evennia.accounts import bots
from evennia.accounts.models import AccountDB from evennia.accounts.models import AccountDB
from evennia.comms.comms import DefaultChannel from evennia.comms.comms import DefaultChannel

View file

@ -1039,7 +1039,7 @@ class CmdSetHelp(CmdHelp):
old_entry.locks.add(lockstring) old_entry.locks.add(lockstring)
except LockException as e: except LockException as e:
old_entry.locks.add(existing_locks) old_entry.locks.add(existing_locks)
self.msg(str(e) + " Locks not changed.") self.msg(str(e) + " Locks not changed.")
else: else:
self.msg(f"Locks for entry '{topicstr}'{aliastxt} changed to: {lockstring}") self.msg(f"Locks for entry '{topicstr}'{aliastxt} changed to: {lockstring}")
return return

View file

@ -94,10 +94,13 @@ class TelnetProtocol(Telnet, StatefulTelnetProtocol, _BASE_SESSION_CLASS):
""" """
try: try:
# Do we have a NAWS update? # Do we have a NAWS update?
if (NAWS in data and if (
len([data[i:i+1] for i in range(0, len(data))]) == 9 and NAWS in data
# Is auto resizing on? and len([data[i : i + 1] for i in range(0, len(data))]) == 9
self.protocol_flags.get('AUTORESIZE')): and
# Is auto resizing on?
self.protocol_flags.get("AUTORESIZE")
):
self.sessionhandler.sync(self.sessionhandler.get(self.sessid)) self.sessionhandler.sync(self.sessionhandler.get(self.sessid))
super().dataReceived(data) super().dataReceived(data)

View file

@ -258,7 +258,9 @@ class TelnetOOB:
gmcp_cmdname = EVENNIA_TO_GMCP[cmdname] gmcp_cmdname = EVENNIA_TO_GMCP[cmdname]
elif "_" in cmdname: elif "_" in cmdname:
# enforce initial capitalization of each command part, leaving fully-capitalized sections intact # enforce initial capitalization of each command part, leaving fully-capitalized sections intact
gmcp_cmdname = ".".join(word.capitalize() if not word.isupper() else word for word in cmdname.split("_")) gmcp_cmdname = ".".join(
word.capitalize() if not word.isupper() else word for word in cmdname.split("_")
)
else: else:
gmcp_cmdname = "Core.%s" % (cmdname if cmdname.istitle() else cmdname.capitalize()) gmcp_cmdname = "Core.%s" % (cmdname if cmdname.istitle() else cmdname.capitalize())

View file

@ -1330,7 +1330,7 @@ def funcparser_callable_conjugate(*args, caller=None, receiver=None, mapping=Non
caller (Object): The object who represents 'you' in the string. caller (Object): The object who represents 'you' in the string.
receiver (Object): The recipient of the string. receiver (Object): The recipient of the string.
mapping (dict, optional): This is a mapping `{key:Object, ...}` and is mapping (dict, optional): This is a mapping `{key:Object, ...}` and is
used to find which object the optional `key` argument refers to. If not given, used to find which object the optional `key` argument refers to. If not given,
the `caller` kwarg is used. the `caller` kwarg is used.
Returns: Returns:
@ -1341,7 +1341,7 @@ def funcparser_callable_conjugate(*args, caller=None, receiver=None, mapping=Non
Notes: Notes:
Note that the verb will not be capitalized. Note that the verb will not be capitalized.
Examples: Examples:
This is often used in combination with the $you/You callables. This is often used in combination with the $you/You callables.
@ -1366,7 +1366,9 @@ def funcparser_callable_conjugate(*args, caller=None, receiver=None, mapping=Non
return second_person_str if obj == receiver else third_person_str return second_person_str if obj == receiver else third_person_str
def funcparser_callable_conjugate_for_pronouns(*args, caller=None, receiver=None, mapping=None, **kwargs): def funcparser_callable_conjugate_for_pronouns(
*args, caller=None, receiver=None, mapping=None, **kwargs
):
""" """
Usage: $pconj(word, [key]) Usage: $pconj(word, [key])
@ -1377,7 +1379,7 @@ def funcparser_callable_conjugate_for_pronouns(*args, caller=None, receiver=None
caller (Object): The object who represents 'you' in the string. caller (Object): The object who represents 'you' in the string.
receiver (Object): The recipient of the string. receiver (Object): The recipient of the string.
mapping (dict, optional): This is a mapping `{key:Object, ...}` and is mapping (dict, optional): This is a mapping `{key:Object, ...}` and is
used to find which object the optional `key` argument refers to. If not given, used to find which object the optional `key` argument refers to. If not given,
the `caller` kwarg is used. the `caller` kwarg is used.
Returns: Returns:
@ -1388,7 +1390,7 @@ def funcparser_callable_conjugate_for_pronouns(*args, caller=None, receiver=None
Notes: Notes:
Note that the verb will not be capitalized. Note that the verb will not be capitalized.
Examples: Examples:
This is often used in combination with the $pron/Pron callables. This is often used in combination with the $pron/Pron callables.
@ -1414,15 +1416,17 @@ def funcparser_callable_conjugate_for_pronouns(*args, caller=None, receiver=None
plural = False plural = False
if hasattr(obj, "gender"): if hasattr(obj, "gender"):
if callable(obj.gender): if callable(obj.gender):
plural = (obj.gender() == "plural") plural = obj.gender() == "plural"
else: else:
plural = (obj.gender == "plural") plural = obj.gender == "plural"
second_person_str, third_person_str = verb_actor_stance_components(verb, plural=plural) second_person_str, third_person_str = verb_actor_stance_components(verb, plural=plural)
return second_person_str if obj == receiver else third_person_str return second_person_str if obj == receiver else third_person_str
def funcparser_callable_pronoun(*args, caller=None, receiver=None, mapping=None, capitalize=False, **kwargs): def funcparser_callable_pronoun(
*args, caller=None, receiver=None, mapping=None, capitalize=False, **kwargs
):
""" """
Usage: $pron(word, [options], [key]) Usage: $pron(word, [options], [key])
@ -1501,7 +1505,7 @@ def funcparser_callable_pronoun(*args, caller=None, receiver=None, mapping=None,
`caller` or not helps determine 2nd vs 3rd-person forms. This is `caller` or not helps determine 2nd vs 3rd-person forms. This is
provided automatically by the funcparser. provided automatically by the funcparser.
mapping (dict, optional): This is a mapping `{key:Object, ...}` and is mapping (dict, optional): This is a mapping `{key:Object, ...}` and is
used to find which object the optional `key` argument refers to. If not given, used to find which object the optional `key` argument refers to. If not given,
the `caller` kwarg is used. the `caller` kwarg is used.
capitalize (bool): The input retains its capitalization. If this is set the output is capitalize (bool): The input retains its capitalization. If this is set the output is
always capitalized. always capitalized.

View file

@ -435,7 +435,11 @@ class TestDefaultCallables(TestCase):
("$You() $conj(smile) at him.", "You smile at him.", "Char1 smiles at him."), ("$You() $conj(smile) at him.", "You smile at him.", "Char1 smiles at him."),
("$You() $conj(smile) at $You(char1).", "You smile at You.", "Char1 smiles at Char1."), ("$You() $conj(smile) at $You(char1).", "You smile at You.", "Char1 smiles at Char1."),
("$You() $conj(smile) at $You(char2).", "You smile at Char2.", "Char1 smiles at You."), ("$You() $conj(smile) at $You(char2).", "You smile at Char2.", "Char1 smiles at You."),
("$You() $conj(smile) while $You(char2) $conj(waves, char2).", "You smile while Char2 waves.", "Char1 smiles while You wave."), (
"$You() $conj(smile) while $You(char2) $conj(waves, char2).",
"You smile while Char2 waves.",
"Char1 smiles while You wave.",
),
( (
"$You(char2) $conj(smile) at $you(char1).", "$You(char2) $conj(smile) at $you(char1).",
"Char2 smile at you.", "Char2 smile at you.",
@ -519,7 +523,12 @@ class TestDefaultCallables(TestCase):
string = "Char1 raises $pron(your, char1) fist as Char2 raises $pron(yours, char2)" string = "Char1 raises $pron(your, char1) fist as Char2 raises $pron(yours, char2)"
expected = "Char1 raises her fist as Char2 raises his" expected = "Char1 raises her fist as Char2 raises his"
ret = self.parser.parse(string, caller=self.obj1, mapping={'char1': self.obj1, 'char2': self.obj2}, raise_errors=True) ret = self.parser.parse(
string,
caller=self.obj1,
mapping={"char1": self.obj1, "char2": self.obj2},
raise_errors=True,
)
self.assertEqual(expected, ret) self.assertEqual(expected, ret)
def test_pronoun_viewpoint(self): def test_pronoun_viewpoint(self):

View file

@ -371,7 +371,7 @@ def verb_actor_stance_components(verb, plural=False):
Args: Args:
verb (str): The verb to analyze verb (str): The verb to analyze
plural (bool): Whether to force 3rd person to plural form plural (bool): Whether to force 3rd person to plural form
Returns: Returns:
tuple: The 2nd person (you) and 3rd person forms of the verb, tuple: The 2nd person (you) and 3rd person forms of the verb,
@ -380,7 +380,7 @@ def verb_actor_stance_components(verb, plural=False):
tense = verb_tense(verb) tense = verb_tense(verb)
them = "*" if plural else "3" them = "*" if plural else "3"
them_suff = "" if plural else "s" them_suff = "" if plural else "s"
if "participle" in tense or "plural" in tense: if "participle" in tense or "plural" in tense:
return (verb, verb) return (verb, verb)
if tense == "infinitive" or "present" in tense: if tense == "infinitive" or "present" in tense: