From cd0776681c94f7976b1361043a561c664f706cc4 Mon Sep 17 00:00:00 2001 From: Dustin Spicuzza Date: Sun, 22 Oct 2023 22:03:55 -0400 Subject: [PATCH] Replace imp.load_source for Python 3.12 compatibility --- pyfrc/physics/core.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pyfrc/physics/core.py b/pyfrc/physics/core.py index b92537d..495129d 100644 --- a/pyfrc/physics/core.py +++ b/pyfrc/physics/core.py @@ -27,10 +27,11 @@ When initialized, it will be passed an instance of this object. """ -import imp +from importlib.machinery import SourceFileLoader import inspect import logging import pathlib +import types import typing import wpilib @@ -103,7 +104,9 @@ def _create_and_attach( if physics_module_path.exists(): # Load the user's physics module if it exists try: - physics_module = imp.load_source("physics", str(physics_module_path)) + loader = SourceFileLoader("physics", str(physics_module_path)) + physics_module = types.ModuleType(loader.name) + loader.exec_module(physics_module) except: logger.exception("Error loading user physics module") raise PhysicsInitException()