Improve type annotations in mesa.time.event#3419
Conversation
|
Performance benchmarks:
|
mesa/time/events.py
Outdated
| # Filter out canceled events and get n smallest in correct chronological order | ||
| return nsmallest(n, (e for e in self._events if not e.CANCELED)) | ||
| valid_events = [e for e in self._events if not e.CANCELED] | ||
| return nsmallest(n, valid_events) |
There was a problem hiding this comment.
This change reintroduces the intermediate list in peek_ahead. In #3413 we switched to a generator expression to avoid the extra allocation and improve performance. We should keep that version here.
There was a problem hiding this comment.
Thanks for pointing that out — you're right.
I’ll restore the generator expression to preserve the optimization from #3413.
We typically use squash and merge, so there is no need to create a clean PR. |
mesa/time/events.py
Outdated
| self, | ||
| time: int | float, | ||
| function: Callable, | ||
| function: Callable[..., Any], |
There was a problem hiding this comment.
The return of the callable is ignored, so there in principle should not be a return from the callable.
There was a problem hiding this comment.
okay, since the return value is ignored, using Callable[..., None] is more appropriate. I've updated the annotation accordingly.
Understood, thanks for clarifying. |
This PR refines type annotations in the
mesa.time.eventmodule.Changes include:
Callableannotations toCallable[..., Any]EventandEventGeneratorNo functional changes were made.
This replaces #3412 with a clean branch containing only the intended changes.