-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Changing generations of names with underscore (#320)
Co-authored-by: developer <developer@local> Co-authored-by: Anthony Shaw <anthony.p.shaw@gmail.com>
1 parent
9b58edb
commit 6686c74
Showing
5 changed files
with
135 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
...Tests/PythonStaticGeneratorTests/FormatClassFromMethods.test_args_underscore.approved.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
// <auto-generated/> | ||
#nullable enable | ||
|
||
using CSnakes.Runtime; | ||
using CSnakes.Runtime.Python; | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Reflection.Metadata; | ||
|
||
using Microsoft.Extensions.Logging; | ||
|
||
[assembly: MetadataUpdateHandler(typeof(Python.Generated.Tests.TestClassExtensions))] | ||
|
||
namespace Python.Generated.Tests; | ||
|
||
public static class TestClassExtensions | ||
{ | ||
private static ITestClass? instance; | ||
|
||
private static ReadOnlySpan<byte> HotReloadHash => "b689cac043d82a1e3830504a67fe21c6"u8; | ||
|
||
public static ITestClass TestClass(this IPythonEnvironment env) | ||
{ | ||
if (instance is null) | ||
{ | ||
instance = new TestClassInternal(env.Logger); | ||
} | ||
Debug.Assert(!env.IsDisposed()); | ||
return instance; | ||
} | ||
|
||
public static void UpdateApplication(Type[]? updatedTypes) | ||
{ | ||
instance?.ReloadModule(); | ||
} | ||
|
||
private class TestClassInternal : ITestClass | ||
{ | ||
private PyObject module; | ||
private readonly ILogger<IPythonEnvironment> logger; | ||
|
||
private PyObject __func_test_with_underscore; | ||
|
||
internal TestClassInternal(ILogger<IPythonEnvironment> logger) | ||
{ | ||
this.logger = logger; | ||
using (GIL.Acquire()) | ||
{ | ||
logger.LogDebug("Importing module {ModuleName}", "test"); | ||
module = Import.ImportModule("test"); | ||
this.__func_test_with_underscore = module.GetAttr("test_with_underscore"); | ||
} | ||
} | ||
|
||
void IReloadableModuleImport.ReloadModule() | ||
{ | ||
logger.LogDebug("Reloading module {ModuleName}", "test"); | ||
using (GIL.Acquire()) | ||
{ | ||
Import.ReloadModule(ref module); | ||
// Dispose old functions | ||
this.__func_test_with_underscore.Dispose(); | ||
// Bind to new functions | ||
this.__func_test_with_underscore = module.GetAttr("test_with_underscore"); | ||
} | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
logger.LogDebug("Disposing module {ModuleName}", "test"); | ||
this.__func_test_with_underscore.Dispose(); | ||
module.Dispose(); | ||
} | ||
|
||
public void TestWithUnderscore(long testx, long testy) | ||
{ | ||
using (GIL.Acquire()) | ||
{ | ||
logger.LogDebug("Invoking Python function: {FunctionName}", "test_with_underscore"); | ||
PyObject __underlyingPythonFunc = this.__func_test_with_underscore; | ||
using PyObject testx_pyObject = PyObject.From(testx)!; | ||
using PyObject testy_pyObject = PyObject.From(testy)!; | ||
using PyObject __result_pyObject = __underlyingPythonFunc.Call(testx_pyObject, testy_pyObject); | ||
return; | ||
} | ||
} | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Represents functions of the Python module <c>test</c>. | ||
/// </summary> | ||
public interface ITestClass : IReloadableModuleImport | ||
{ | ||
/// <summary> | ||
/// Invokes the Python function <c>test_with_underscore</c>: | ||
/// <code><![CDATA[ | ||
/// def test_with_underscore(test_x: int, test_y: int) -> None: ... | ||
/// ]]></code> | ||
/// </summary> | ||
void TestWithUnderscore(long testx, long testy); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
def test_with_underscore(test_x: int, test_y: int) -> None: | ||
return None |