Skip to content
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

chore(deps): add Python 3.12 support #3395

Merged
merged 8 commits into from
Nov 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
removed get_parameters, replaced by direct call to inspect
  • Loading branch information
behackl committed Nov 4, 2023
commit aac89bf8d71b34c7c6892a5ad0c5bd3aaacb500b
6 changes: 2 additions & 4 deletions manim/animation/speedmodifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

from __future__ import annotations

import inspect
import types
from typing import Callable

from numpy import piecewise

from manim.utils.simple_functions import get_parameters

from ..animation.animation import Animation, Wait, prepare_animation
from ..animation.composition import AnimationGroup
from ..mobject.mobject import Mobject, Updater, _AnimationBuilder
Expand Down Expand Up @@ -260,8 +259,7 @@ def add_updater(
:class:`.ChangeSpeed`
:meth:`.Mobject.add_updater`
"""
parameters = get_parameters(update_function)
if "dt" in parameters:
if "dt" in inspect.signature(update_function).parameters:
mobject.add_updater(
lambda mob, dt: update_function(
mob, ChangeSpeed.dt if ChangeSpeed.is_changing_dt else dt
Expand Down
17 changes: 11 additions & 6 deletions manim/mobject/mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@


import copy
import inspect
import itertools as it
import operator as op
import random
Expand Down Expand Up @@ -47,7 +48,6 @@
from ..utils.exceptions import MultiAnimationOverrideException
from ..utils.iterables import list_update, remove_list_redundancies
from ..utils.paths import straight_path
from ..utils.simple_functions import get_parameters
from ..utils.space_ops import angle_between_vectors, normalize, rotation_matrix

# TODO: Explain array_attrs
Expand Down Expand Up @@ -844,8 +844,7 @@ def update(self, dt: float = 0, recursive: bool = True):
if self.updating_suspended:
return self
for updater in self.updaters:
parameters = get_parameters(updater)
if "dt" in parameters:
if "dt" in inspect.signature(updater).parameters:
updater(self, dt)
else:
updater(self)
Expand All @@ -870,7 +869,10 @@ def get_time_based_updaters(self) -> list[Updater]:
:meth:`has_time_based_updater`

"""
return [updater for updater in self.updaters if "dt" in get_parameters(updater)]
return [
updater for updater in self.updaters
if "dt" in inspect.signature(updater).parameters
]

def has_time_based_updater(self) -> bool:
"""Test if ``self`` has a time based updater.
Expand All @@ -886,7 +888,10 @@ def has_time_based_updater(self) -> bool:
:meth:`get_time_based_updaters`

"""
return any("dt" in get_parameters(updater) for updater in self.updaters)
return any(
"dt" in inspect.signature(updater).parameters
for updater in self.updaters
)

def get_updaters(self) -> list[Updater]:
"""Return all updaters.
Expand Down Expand Up @@ -979,7 +984,7 @@ def construct(self):
else:
self.updaters.insert(index, update_function)
if call_updater:
parameters = get_parameters(update_function)
parameters = inspect.signature(update_function).parameters
if "dt" in parameters:
update_function(self, 0)
else:
Expand Down
4 changes: 2 additions & 2 deletions manim/mobject/opengl/opengl_mobject.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import copy
import inspect
import itertools as it
import random
import sys
Expand Down Expand Up @@ -29,7 +30,6 @@
uniq_chain,
)
from manim.utils.paths import straight_path
from manim.utils.simple_functions import get_parameters
from manim.utils.space_ops import (
angle_between_vectors,
normalize,
Expand Down Expand Up @@ -1375,7 +1375,7 @@ def get_family_updaters(self):
return list(it.chain(*(sm.get_updaters() for sm in self.get_family())))

def add_updater(self, update_function, index=None, call_updater=False):
if "dt" in get_parameters(update_function):
if "dt" in inspect.signature(update_function).parameters:
updater_list = self.time_based_updaters
else:
updater_list = self.non_time_updaters
Expand Down
4 changes: 2 additions & 2 deletions manim/renderer/shader.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import inspect
import re
import textwrap
from pathlib import Path
Expand All @@ -9,7 +10,6 @@

from .. import config
from ..utils import opengl
from ..utils.simple_functions import get_parameters

SHADER_FOLDER = Path(__file__).parent / "shaders"
shader_program_cache: dict = {}
Expand Down Expand Up @@ -199,7 +199,7 @@ def get_updaters(self):
return self.time_based_updaters + self.non_time_updaters

def add_updater(self, update_function, index=None, call_updater=True):
if "dt" in get_parameters(update_function):
if "dt" in inspect.signature(update_function).parameters:
updater_list = self.time_based_updaters
else:
updater_list = self.non_time_updaters
Expand Down
19 changes: 0 additions & 19 deletions manim/utils/simple_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"binary_search",
"choose",
"clip",
"get_parameters",
"sigmoid",
]

Expand Down Expand Up @@ -117,24 +116,6 @@ def clip(a, min_a, max_a):
return a


def get_parameters(function: Callable) -> MappingProxyType[str, inspect.Parameter]:
"""Return the parameters of ``function`` as an ordered mapping of parameters'
names to their corresponding ``Parameter`` objects.

Examples
--------
::

>>> # Skipping test because of gh-101446 (cypthon)
>>> get_parameters(get_parameters) # doctest: +SKIP
mappingproxy(OrderedDict([('function', <Parameter "function: 'Callable'">)]))

>>> tuple(get_parameters(choose))
('n', 'k')
"""
return inspect.signature(function).parameters


def sigmoid(x: float) -> float:
r"""Returns the output of the logistic function.

Expand Down