Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4529fde

Browse files
committed
Names of .NET types (e.g.str(__class__)) changed to better support generic types
1 parent38e0b5d commit4529fde

File tree

2 files changed

+61
-12
lines changed

2 files changed

+61
-12
lines changed

‎CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ One must now either use enum members (e.g. `MyEnum.Option`), or use enum constru
5151
- BREAKING: custom encoders are no longer called for instances of`System.Type`
5252
-`PythonException.Restore` no longer clears`PythonException` instance.
5353
- Replaced the old`__import__` hook hack with a PEP302-style Meta Path Loader
54+
- BREAKING: Names of .NET types (e.g.`str(__class__)`) changed to better support generic types
5455

5556
###Fixed
5657

‎src/runtime/typemanager.cs

Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -211,18 +211,7 @@ internal static unsafe PyType CreateType(Type impl)
211211

212212
staticPyTypeCreateClass(TypeclrType)
213213
{
214-
// Cleanup the type name to get rid of funny nested type names.
215-
stringname=$"clr.{clrType.FullName}";
216-
inti=name.LastIndexOf('+');
217-
if(i>-1)
218-
{
219-
name=name.Substring(i+1);
220-
}
221-
i=name.LastIndexOf('.');
222-
if(i>-1)
223-
{
224-
name=name.Substring(i+1);
225-
}
214+
stringname=GetPythonTypeName(clrType);
226215

227216
usingvarbaseTuple=GetBaseTypeTuple(clrType);
228217

@@ -251,6 +240,65 @@ static PyType CreateClass(Type clrType)
251240
returnpyType;
252241
}
253242

243+
staticstringGetPythonTypeName(TypeclrType)
244+
{
245+
varresult=newSystem.Text.StringBuilder();
246+
GetPythonTypeName(clrType,target:result);
247+
returnresult.ToString();
248+
}
249+
250+
staticvoidGetPythonTypeName(TypeclrType,System.Text.StringBuildertarget)
251+
{
252+
if(clrType.IsGenericType)
253+
{
254+
stringfullName=clrType.GetGenericTypeDefinition().FullName;
255+
intargCountIndex=fullName.LastIndexOf('`');
256+
if(argCountIndex>=0)
257+
{
258+
stringnonGenericFullName=fullName.Substring(0,argCountIndex);
259+
stringnonGenericName=CleanupFullName(nonGenericFullName);
260+
target.Append(nonGenericName);
261+
262+
vararguments=clrType.GetGenericArguments();
263+
target.Append('[');
264+
for(intargIndex=0;argIndex<arguments.Length;argIndex++)
265+
{
266+
if(argIndex!=0)
267+
{
268+
target.Append(',');
269+
}
270+
271+
GetPythonTypeName(arguments[argIndex],target);
272+
}
273+
274+
target.Append(']');
275+
return;
276+
}
277+
}
278+
279+
stringname=CleanupFullName(clrType.FullName);
280+
target.Append(name);
281+
}
282+
283+
staticstringCleanupFullName(stringfullTypeName)
284+
{
285+
// Cleanup the type name to get rid of funny nested type names.
286+
stringname="clr."+fullTypeName;
287+
inti=name.LastIndexOf('+');
288+
if(i>-1)
289+
{
290+
name=name.Substring(i+1);
291+
}
292+
293+
i=name.LastIndexOf('.');
294+
if(i>-1)
295+
{
296+
name=name.Substring(i+1);
297+
}
298+
299+
returnname;
300+
}
301+
254302
staticBorrowedReferenceInitializeBases(PyTypepyType,PyTuplebaseTuple)
255303
{
256304
Debug.Assert(baseTuple.Length()>0);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp