Skip to content

Commit

Permalink
Minor docstring cleanup and refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
benmoran56 committed Jan 5, 2024
1 parent 900c817 commit 323254f
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions esper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@

from itertools import count as _count


version = '3.2'
__version__ = version
__version__ = version = '3.3'


###################
Expand All @@ -50,6 +48,7 @@ def dispatch_event(name: str, *args: _Any) -> None:

def _make_callback(name: str) -> _Callable[[_Any], None]:
"""Create an internal callback to remove dead handlers."""

def callback(weak_method: _Any) -> None:
event_registry[name].remove(weak_method)
if not event_registry[name]:
Expand Down Expand Up @@ -128,7 +127,6 @@ def process(self, *args: _Any, **kwargs: _Any) -> None:
raise NotImplementedError



###################
# ECS functions
###################
Expand Down Expand Up @@ -510,26 +508,25 @@ def timed_process(*args: _Any, **kwargs: _Any) -> None:
for processor in _processors:
start_time = _time.process_time()
processor.process(*args, **kwargs)
process_time = int(round((_time.process_time() - start_time) * 1000, 2))
process_times[processor.__class__.__name__] = process_time
process_times[processor.__class__.__name__] = int((_time.process_time() - start_time) * 1000)


def list_worlds() -> _List[str]:
"""A list all World context names."""
return list(_context_map.keys())
return list(_context_map)


def delete_world(name: str) -> None:
"""Delete a World context.
This will completely delete the World, including any entities
This will completely delete the World, including all entities
that are contained within it.
Raises a NameError if you attempt to delete the currently
Raises `PermissionError` if you attempt to delete the currently
active World context.
"""
if _current_context == name:
raise NameError("Cannot delete active World context.")
raise PermissionError("The active World context cannot be deleted.")

del _context_map[name]

Expand All @@ -538,16 +535,16 @@ def switch_world(name: str) -> None:
"""Switch to a new World context by name.
Esper can have one or more "Worlds". Each World is a dedicated
context, and does not share Entities, Components, etc. For
some game designs, it simplifies things to use a dedicated
World for each scene. For other designs, a single World may
be sufficient. This function will allow you to create and
switch between as many World contexts as required. If the
requested name does not exist, a new context is created
automatically with that name.
.. note:: At startup, a "default" context exists, and is
already active.
context, and does not share Entities, Components, events, etc.
Some game designs can benefit from using a dedicated World
for each scene. For other designs, a single World may
be sufficient.
This function will allow you to create and switch between as
many World contexts as required. If the requested name does not
exist, a new context is created automatically with that name.
.. note:: At startup, a "default" World context is active.
"""
if name not in _context_map:
# Create a new context if the name does not already exist:
Expand Down Expand Up @@ -576,4 +573,4 @@ def current_world() -> str:
To switch World contexts, see :py:func:`esper.switch_world`.
"""
return _current_context
return _current_context

0 comments on commit 323254f

Please sign in to comment.