Skip to content

Commit 78f0926

Browse files
authored
Merge pull request #223 from robotpy/py312
Replace imp.load_source for Python 3.12 compatibility
2 parents 1263861 + cd07766 commit 78f0926

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

pyfrc/physics/core.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@
2727
When initialized, it will be passed an instance of this object.
2828
"""
2929

30-
import imp
30+
from importlib.machinery import SourceFileLoader
3131
import inspect
3232
import logging
3333
import pathlib
34+
import types
3435
import typing
3536

3637
import wpilib
@@ -103,7 +104,9 @@ def _create_and_attach(
103104
if physics_module_path.exists():
104105
# Load the user's physics module if it exists
105106
try:
106-
physics_module = imp.load_source("physics", str(physics_module_path))
107+
loader = SourceFileLoader("physics", str(physics_module_path))
108+
physics_module = types.ModuleType(loader.name)
109+
loader.exec_module(physics_module)
107110
except:
108111
logger.exception("Error loading user physics module")
109112
raise PhysicsInitException()

0 commit comments

Comments
 (0)