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

Support clr.GetClrType() - as in IronPython#433

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
vmuriart merged 7 commits intopythonnet:masterfromvivainio:master
Mar 24, 2017
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 deletionsAUTHORS.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,6 +32,7 @@
- Sam Winstanley ([@swinstanley](https://github.com/swinstanley))
- Sean Freitag ([@cowboygneox](https://github.com/cowboygneox))
- Serge Weinstock ([@sweinst](https://github.com/sweinst))
- Ville M. Vainio ([@vivainio](https://github.com/vivainio))
- Virgil Dupras ([@hsoft](https://github.com/hsoft))
- Wenguang Yang ([@yagweb](https://github.com/yagweb))
- Xavier Dupré ([@sdpython](https://github.com/sdpython))
Expand Down
2 changes: 1 addition & 1 deletionCHANGELOG.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,7 +8,7 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
## [unreleased][]

### Added

- Added clr.GetClrType (#432)(#433)
- Added `Foo` feature

### Changed
Expand Down
17 changes: 17 additions & 0 deletionssrc/runtime/moduleobject.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -403,6 +403,23 @@ public static Assembly AddReference(string name)
return assembly;
}

/// <summary>
/// Get a Type instance for a class object.
/// clr.GetClrType(IComparable) gives you the Type for IComparable,
/// that you can e.g. perform reflection on. Similar to typeof(IComparable) in C#
/// or clr.GetClrType(IComparable) in IronPython.
///
/// </summary>
/// <param name="type"></param>
/// <returns>The Type object</returns>

[ModuleFunction]
[ForbidPythonThreads]
public static Type GetClrType(Type type)
{
return type;
}

[ModuleFunction]
[ForbidPythonThreads]
public static string FindAssembly(string name)
Expand Down
20 changes: 20 additions & 0 deletionssrc/tests/test_module.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -352,6 +352,26 @@ def test_clr_add_reference():
with pytest.raises(FileNotFoundException):
AddReference("somethingtotallysilly")

def test_clr_get_clr_type():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

can you add the test to invoke the ArgumentException error?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Done

"""Test clr.GetClrType()."""
from clr import GetClrType
import System
from System import IComparable
from System import ArgumentException
assert GetClrType(System.String).FullName == "System.String"
comparable = GetClrType(IComparable)
assert comparable.FullName == "System.IComparable"
assert comparable.IsInterface
assert GetClrType(int).FullName == "System.Int32"
assert GetClrType(str).FullName == "System.String"
assert GetClrType(float).FullName == "System.Double"
dblarr = System.Array[System.Double]
assert GetClrType(dblarr).FullName == "System.Double[]"

with pytest.raises(TypeError):
GetClrType(1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

can you compare also against types, not instance of types?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Can you elaborate, what kind of comparison I should add?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

GetClrType(int), GetClrType(str)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Check lines 365-367 in the diff :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Oh, I see now let's wait for@filmor to approve

with pytest.raises(TypeError):
GetClrType("thiswillfail")

def test_assembly_load_thread_safety():
from Python.Test import ModuleTest
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp