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

Drop the long-deprecated CLR.* alias#1319

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
lostmsu merged 1 commit intopythonnet:masterfromfilmor:drop-uppercase-clr
Dec 12, 2020
Merged
Show file tree
Hide file tree
Changes fromall commits
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
1 change: 1 addition & 0 deletionsCHANGELOG.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -25,6 +25,7 @@ details about the cause of the failure
if you need to "downcast" to the implementation class.
- BREAKING: Parameters marked with `ParameterAttributes.Out` are no longer returned in addition
to the regular method return value (unless they are passed with `ref` or `out` keyword).
- BREAKING: Drop support for the long-deprecated CLR.* prefix.

### Fixed

Expand Down
80 changes: 33 additions & 47 deletionssrc/runtime/importhook.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -124,7 +124,7 @@ internal static void Shutdown()

internal static void SaveRuntimeData(RuntimeDataStorage storage)
{
// Increment the reference counts here so that the objects don't
// Increment the reference counts here so that the objects don't
// get freed in Shutdown.
Runtime.XIncref(py_clr_module);
Runtime.XIncref(root.pyHandle);
Expand DownExpand Up@@ -241,12 +241,8 @@ public static IntPtr __import__(IntPtr self, IntPtr args, IntPtr kw)
// Check these BEFORE the built-in import runs; may as well
// do the Incref()ed return here, since we've already found
// the module.
if (mod_name == "clr" || mod_name == "CLR")
if (mod_name == "clr")
{
if (mod_name == "CLR")
{
Exceptions.deprecation("The CLR module is deprecated. Please use 'clr'.");
}
IntPtr clr_module = GetCLRModule(fromList);
if (clr_module != IntPtr.Zero)
{
Expand All@@ -262,51 +258,41 @@ public static IntPtr __import__(IntPtr self, IntPtr args, IntPtr kw)
string realname = mod_name;
string clr_prefix = null;

if (mod_name.StartsWith("CLR."))
// 2010-08-15: Always seemed smart to let python try first...
// This shaves off a few tenths of a second on test_module.py
// and works around a quirk where 'sys' is found by the
// LoadImplicit() deprecation logic.
// Turns out that the AssemblyManager.ResolveHandler() checks to see if any
// Assembly's FullName.ToLower().StartsWith(name.ToLower()), which makes very
// little sense to me.
IntPtr res = Runtime.PyObject_Call(py_import, args, kw);
if (res != IntPtr.Zero)
{
clr_prefix = "CLR."; // prepend when adding the module to sys.modules
realname = mod_name.Substring(4);
string msg = $"Importing from the CLR.* namespace is deprecated. Please import '{realname}' directly.";
Exceptions.deprecation(msg);
}
else
{
// 2010-08-15: Always seemed smart to let python try first...
// This shaves off a few tenths of a second on test_module.py
// and works around a quirk where 'sys' is found by the
// LoadImplicit() deprecation logic.
// Turns out that the AssemblyManager.ResolveHandler() checks to see if any
// Assembly's FullName.ToLower().StartsWith(name.ToLower()), which makes very
// little sense to me.
IntPtr res = Runtime.PyObject_Call(py_import, args, kw);
if (res != IntPtr.Zero)
// There was no error.
if (fromlist && IsLoadAll(fromList))
{
// There was no error.
if (fromlist && IsLoadAll(fromList))
{
var mod = ManagedType.GetManagedObject(res) as ModuleObject;
mod?.LoadNames();
}
return res;
}
// There was an error
if (!Exceptions.ExceptionMatches(Exceptions.ImportError))
{
// and it was NOT an ImportError; bail out here.
return IntPtr.Zero;
var mod = ManagedType.GetManagedObject(res) as ModuleObject;
mod?.LoadNames();
}
return res;
}
// There was an error
if (!Exceptions.ExceptionMatches(Exceptions.ImportError))
{
// and it was NOT an ImportError; bail out here.
return IntPtr.Zero;
}

if (mod_name == string.Empty)
{
// Most likely a missing relative import.
// For example site-packages\bs4\builder\__init__.py uses it to check if a package exists:
// from . import _html5lib
// We don't support them anyway
return IntPtr.Zero;
}
// Otherwise, just clear the it.
Exceptions.Clear();
if (mod_name == string.Empty)
{
// Most likely a missing relative import.
// For example site-packages\bs4\builder\__init__.py uses it to check if a package exists:
// from . import _html5lib
// We don't support them anyway
return IntPtr.Zero;
}
// Otherwise, just clear the it.
Exceptions.Clear();

string[] names = realname.Split('.');

Expand DownExpand Up@@ -372,7 +358,7 @@ public static IntPtr __import__(IntPtr self, IntPtr args, IntPtr kw)
// Add the module to sys.modules
Runtime.PyDict_SetItemString(modules, tail.moduleName, tail.pyHandle);

// If imported from CLR addCLR.<modulename> to sys.modules as well
// If imported from CLR addclr.<modulename> to sys.modules as well
if (clr_prefix != null)
{
Runtime.PyDict_SetItemString(modules, clr_prefix + tail.moduleName, tail.pyHandle);
Expand Down
1 change: 0 additions & 1 deletionsrc/runtime/runtime.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -492,7 +492,6 @@ private static void ClearClrModules()
private static void RemoveClrRootModule()
{
var modules = PyImport_GetModuleDict();
PyDictTryDelItem(modules, "CLR");
PyDictTryDelItem(modules, "clr");
PyDictTryDelItem(modules, "clr._extra");
}
Expand Down
2 changes: 1 addition & 1 deletionsrc/runtime/typemanager.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -176,7 +176,7 @@ internal static IntPtr CreateType(Type impl)
internal static IntPtr CreateType(ManagedType impl, Type clrType)
{
// Cleanup the type name to get rid of funny nested type names.
string name ="CLR." +clrType.FullName;
string name =$"clr.{clrType.FullName}";
int i = name.LastIndexOf('+');
if (i > -1)
{
Expand Down
4 changes: 2 additions & 2 deletionssrc/testing/threadtest.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,8 +11,8 @@ public class ThreadTest
private static PyObject module;

private static string testmod =
"importCLR\n" +
"fromCLR.Python.Test import ThreadTest\n" +
"importclr\n" +
"from Python.Test import ThreadTest\n" +
"\n" +
"def echostring(value):\n" +
" return value\n" +
Expand Down
2 changes: 1 addition & 1 deletionsrc/tests/test_clrmethod.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,7 +14,7 @@ def __init__(self):
@clr.clrmethod(int, [int])
def test(self, x):
return x*2

def get_X(self):
return self._x
def set_X(self, value):
Expand Down
233 changes: 0 additions & 233 deletionssrc/tests/test_compat.py
View file
Open in desktop

This file was deleted.

Loading

[8]ページ先頭

©2009-2025 Movatter.jp