Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 12, 2020
Merged
Show file tree
Hide file tree
Changes from all 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 deletions CHANGELOG.md
Original file line number Diff line number Diff 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 deletions src/runtime/importhook.cs
Original file line number Diff line number Diff 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 Down Expand 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 Down Expand 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 add CLR.<modulename> to sys.modules as well
// If imported from CLR add clr.<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 deletion src/runtime/runtime.cs
Original file line number Diff line number Diff 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 deletion src/runtime/typemanager.cs
Original file line number Diff line number Diff 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 deletions src/testing/threadtest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public class ThreadTest
private static PyObject module;

private static string testmod =
"import CLR\n" +
"from CLR.Python.Test import ThreadTest\n" +
"import clr\n" +
"from Python.Test import ThreadTest\n" +
"\n" +
"def echostring(value):\n" +
" return value\n" +
Expand Down
2 changes: 1 addition & 1 deletion src/tests/test_clrmethod.py
Original file line number Diff line number Diff 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 deletions src/tests/test_compat.py

This file was deleted.

Loading