Implement support for DLR get/set by filmor · Pull Request #2706 · pythonnet/pythonnet
Repository navigation
Implement support for DLR get/set - #2706
Merged
filmor merged 5 commits into master from dlr May 15, 2026
Merged
Implement support for DLR get/set #2706 filmor merged 5 commits into master from dlr
Conversation
filmor commented Apr 18, 2026 · edited Loading
Copy link Copy Markdown
Member
Implements #72 and should thus fix #2696 .
@spkl Could you try out this branch?
filmor requested a review from lostmsu April 18, 2026 13:51 filmor force-pushed the dlr branch 3 times, most recently from34eff30 to
ac40869
Compare
April 18, 2026 17:58 filmor marked this pull request as ready for review April 20, 2026 07:23
spkl commented Apr 20, 2026
Copy link Copy Markdown
|
@filmor If I understand this correctly, one wouldn't even need the dynamic.py script anymore for DynamicObject access to work, correct? That seems great :) |
filmor commented Apr 20, 2026
Copy link Copy Markdown
Member
Author
|
@spkl Yes, the dynamic support would be integrated. To build a wheel, the simplest way is to get |
spkl commented Apr 20, 2026 · edited Loading
Copy link Copy Markdown
|
OK so I did a little digging and found out that I can Getting the value of dynamic properties seems to work, but I encountered a problem when setting dynamic properties. This is what I observed when running a script like this: x = obj.MyProp obj.MyProp = None y = obj.MyProp For line 1, |
View reviewed changes
filmor force-pushed the dlr branch 4 times, most recently from
fdfa219 to
6d1572e
Compare
May 5, 2026 19:56
filmor commented May 6, 2026
Copy link Copy Markdown
Member
Author
|
@spkl Could you test again whether this works for you? |
6d1572e to
88e8bd3
Compare
May 6, 2026 13:43
spkl commented May 6, 2026
Copy link Copy Markdown
|
Will do ASAP and let you know |
spkl commented May 7, 2026
Copy link Copy Markdown
|
OK @filmor , this is pretty great. With the current version from this branch and with all previous workarounds removed, all of our test cases pass. 🎉 Performance is also improved, which I could see in our two dedicated performance tests. These tests don't strictly measure pythonnet performance, but that is a significant part of them. Numbers are normalized to fractions, lower is better.
There is one significant behavioral difference that I observed: With past solutions, there was always an AttributeError when setting an attribute for which TrySetMember returns false (= which does not exist). With this branch, the attribute is now set on the Python side without any error. This can be problematic, because it can mask errors / typos in scripts and make troubleshooting harder. I don't know if this was intended. If it is, we can probably find a different solution. I tried to find a workaround for that behavior and discovered something else where I'm not sure if it's correct: When throwing an exception in TrySetMember, the process crashes with a .NET exception, so there is no Python traceback to pinpoint the error location. In contrast, when throwing an exception in Try Get Member, it comes up as an AttributeError with Python traceback output. Because we support running in different environments and Python versions, we probably need to implement automatic switching between DynamicObject workaround and first-class DLR support in pythonnet. Is there a way to find out if the currently loaded pythonnet module has DLR support? An information about the version would also work, but pythonnet currently has no |
filmor commented May 7, 2026
Copy link Copy Markdown
Member
Author
|
I'll try to handle these cases, definitely not intentional :) If you need to get a package's version in your code, please use |
88e8bd3 to
d629b87
Compare
May 7, 2026 17:01 filmor requested a review from lostmsu May 7, 2026 17:02 greateggsgreg added a commit to greateggsgreg/pythonnet that referenced this pull request May 9, 2026
Propagate exceptions from TryGetMember in tp_getattro_dlr_proxy
5c3421f
The dynamic getter swallowed any exception from TryGetMember and returned default to Python with the prior AttributeError still set, so user code observed a misleading AttributeError instead of the real failure. Set a Python exception in the catch arm. We use RuntimeError with the message string rather than Converter.ToPython(e) because wrapping the CLR exception object can trigger type initialisation that re-enters this same slot on the live dynamic object, producing infinite recursion. Mirrors the symmetry already present in the setter (pythonnet#2706 review, @lostmsu) and adds a regression test alongside the existing ThrowingSetDynamicObject coverage. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>greateggsgreg mentioned this pull request May 9, 2026 dlr branch fix - Propagate exceptions from TryGetMember in tp_getattro_dlr_proxy #2718 Merged greateggsgreg added a commit to greateggsgreg/pythonnet that referenced this pull request May 9, 2026
Propagate exceptions from TryGetMember in tp_getattro_dlr_proxy
5d64310
The dynamic getter swallowed any exception from TryGetMember and returned default to Python with the prior AttributeError still set, so user code observed a misleading AttributeError instead of the real failure. Set a Python exception in the catch arm. We use RuntimeError with the message string rather than Converter.ToPython(e) because wrapping the CLR exception object can trigger type initialisation that re-enters this same slot on the live dynamic object, producing infinite recursion. Mirrors the symmetry already present in the setter (pythonnet#2706 review, @lostmsu) and adds a regression test alongside the existing ThrowingSetDynamicObject coverage.
greateggsgreg commented May 10, 2026 · edited Loading
Copy link Copy Markdown
Contributor
|
#2718 should fix the |
Propagate exceptions from TryGetMember in tp_getattro_dlr_proxy (#2718)
da48ef7
The dynamic getter swallowed any exception from TryGetMember and returned default to Python with the prior AttributeError still set, so user code observed a misleading AttributeError instead of the real failure. Set a Python exception in the catch arm. We use RuntimeError with the message string rather than Converter.ToPython(e) because wrapping the CLR exception object can trigger type initialisation that re-enters this same slot on the live dynamic object, producing infinite recursion. Mirrors the symmetry already present in the setter (#2706 review, @lostmsu) and adds a regression test alongside the existing ThrowingSetDynamicObject coverage.
alexchandel commented May 11, 2026
Copy link Copy Markdown
|
You want to rebase this and retest with the |
Cache HasClrMember and align DLR setter exception path
bcf8c0d
- Cache HasClrMember reflection per (Type, name) so tp_getattro_dlr_proxy / tp_setattro_dlr_proxy avoid repeated GetMember() calls on every attribute access of DLR-aware objects. - Mirror tp_setattro_dlr_proxy's catch arm to the getter's safer SetError(RuntimeError, e.Message) shape instead of SetError(Exception), keeping both slots re-entry-safe on live dynamic objects. Related to pythonnet#2706.filmor pushed a commit that referenced this pull request May 12, 2026
Propagate exceptions from TryGetMember in tp_getattro_dlr_proxy (#2718)
93c8e38
The dynamic getter swallowed any exception from TryGetMember and returned default to Python with the prior AttributeError still set, so user code observed a misleading AttributeError instead of the real failure. Set a Python exception in the catch arm. We use RuntimeError with the message string rather than Converter.ToPython(e) because wrapping the CLR exception object can trigger type initialisation that re-enters this same slot on the live dynamic object, producing infinite recursion. Mirrors the symmetry already present in the setter (#2706 review, @lostmsu) and adds a regression test alongside the existing ThrowingSetDynamicObject coverage.filmor force-pushed the dlr branch from
da48ef7 to
93c8e38
Compare
May 12, 2026 19:56 filmor pushed a commit that referenced this pull request May 12, 2026
Cache HasClrMember and align DLR setter exception path
fef6f35
- Cache HasClrMember reflection per (Type, name) so tp_getattro_dlr_proxy / tp_setattro_dlr_proxy avoid repeated GetMember() calls on every attribute access of DLR-aware objects. - Mirror tp_setattro_dlr_proxy's catch arm to the getter's safer SetError(RuntimeError, e.Message) shape instead of SetError(Exception), keeping both slots re-entry-safe on live dynamic objects. Related to #2706.filmor pushed a commit that referenced this pull request May 12, 2026
Propagate exceptions from TryGetMember in tp_getattro_dlr_proxy (#2718)
789726c
The dynamic getter swallowed any exception from TryGetMember and returned default to Python with the prior AttributeError still set, so user code observed a misleading AttributeError instead of the real failure. Set a Python exception in the catch arm. We use RuntimeError with the message string rather than Converter.ToPython(e) because wrapping the CLR exception object can trigger type initialisation that re-enters this same slot on the live dynamic object, producing infinite recursion. Mirrors the symmetry already present in the setter (#2706 review, @lostmsu) and adds a regression test alongside the existing ThrowingSetDynamicObject coverage.filmor force-pushed the dlr branch from
fef6f35 to
e99538e
Compare
May 12, 2026 20:25 filmor pushed a commit that referenced this pull request May 12, 2026
Cache HasClrMember and align DLR setter exception path
e99538e
- Cache HasClrMember reflection per (Type, name) so tp_getattro_dlr_proxy / tp_setattro_dlr_proxy avoid repeated GetMember() calls on every attribute access of DLR-aware objects. - Mirror tp_setattro_dlr_proxy's catch arm to the getter's safer SetError(RuntimeError, e.Message) shape instead of SetError(Exception), keeping both slots re-entry-safe on live dynamic objects. Related to #2706.filmor pushed a commit that referenced this pull request May 13, 2026
Propagate exceptions from TryGetMember in tp_getattro_dlr_proxy (#2718)
a2ed667
The dynamic getter swallowed any exception from TryGetMember and returned default to Python with the prior AttributeError still set, so user code observed a misleading AttributeError instead of the real failure. Set a Python exception in the catch arm. We use RuntimeError with the message string rather than Converter.ToPython(e) because wrapping the CLR exception object can trigger type initialisation that re-enters this same slot on the live dynamic object, producing infinite recursion. Mirrors the symmetry already present in the setter (#2706 review, @lostmsu) and adds a regression test alongside the existing ThrowingSetDynamicObject coverage.filmor pushed a commit that referenced this pull request May 13, 2026
Cache HasClrMember and align DLR setter exception path
a3c2069
- Cache HasClrMember reflection per (Type, name) so tp_getattro_dlr_proxy / tp_setattro_dlr_proxy avoid repeated GetMember() calls on every attribute access of DLR-aware objects. - Mirror tp_setattro_dlr_proxy's catch arm to the getter's safer SetError(RuntimeError, e.Message) shape instead of SetError(Exception), keeping both slots re-entry-safe on live dynamic objects. Related to #2706.filmor force-pushed the dlr branch from
e99538e to
a3c2069
Compare
May 13, 2026 05:28
filmor commented May 13, 2026
Copy link Copy Markdown
Member
Author
|
@spkl Can you please test out the latest version? |
spkl commented May 13, 2026
Copy link Copy Markdown
|
@filmor All good from my side 👍 |
Implement support for DLR get/set
5dacfb4
Use explicit IsNull on BorrowedReference
69ba861
Catch errors in setting/deleting properties
2408c43
- Catch exceptions in TrySet/DeleteMember - Convert the exceptions into Python exceptions - Add tests for the remaining cases - Add a note on why the field has to be lazily initialized (general issue with derived classes)
Propagate exceptions from TryGetMember in tp_getattro_dlr_proxy (#2718)
8b12b56
The dynamic getter swallowed any exception from TryGetMember and returned default to Python with the prior AttributeError still set, so user code observed a misleading AttributeError instead of the real failure. Set a Python exception in the catch arm. We use RuntimeError with the message string rather than Converter.ToPython(e) because wrapping the CLR exception object can trigger type initialisation that re-enters this same slot on the live dynamic object, producing infinite recursion. Mirrors the symmetry already present in the setter (#2706 review, @lostmsu) and adds a regression test alongside the existing ThrowingSetDynamicObject coverage.
Cache HasClrMember and align DLR setter exception path
3a08990
- Cache HasClrMember reflection per (Type, name) so tp_getattro_dlr_proxy / tp_setattro_dlr_proxy avoid repeated GetMember() calls on every attribute access of DLR-aware objects. - Mirror tp_setattro_dlr_proxy's catch arm to the getter's safer SetError(RuntimeError, e.Message) shape instead of SetError(Exception), keeping both slots re-entry-safe on live dynamic objects. Related to #2706.filmor force-pushed the dlr branch from
a3c2069 to
3a08990
Compare
May 15, 2026 19:57 filmor merged commit
27caf5c
into
master
May 15, 2026
29 of 30 checks passed
filmor
deleted the
dlr
branch
May 15, 2026 19:58
This was referenced May 24, 2026
Bump pythonnet from 3.0.5 to 3.1.0
zcsizmadia/PyDotNet#12
Merged
chore: Bump pythonnet from 3.0.5 to 3.1.0
apache/arrow-dotnet#364
Merged
CurtHagenlocher
pushed a commit
to apache/arrow-dotnet
that referenced
this pull request
May 25, 2026
chore: Bump pythonnet from 3.0.5 to 3.1.0 (#364)
5c6a0c9
Updated [pythonnet](https://github.com/pythonnet/pythonnet) from 3.0.5 to 3.1.0. <details> <summary>Release notes</summary> _Sourced from [pythonnet's releases](https://github.com/pythonnet/pythonnet/releases)._ ## 3.1.0 ## What's Changed * ci: properly exclude job by @RobPasMue in pythonnet/pythonnet#2542 * `__delitem__` for `IList<T>` and `IDictionary<K,V>` by @lostmsu in pythonnet/pythonnet#2533 * Fix docs workflow by @filmor in pythonnet/pythonnet#2584 * Drop EOLd Python versions by @filmor in pythonnet/pythonnet#2632 * Bump setuptools and adjust license information by @filmor in pythonnet/pythonnet#2633 * Minimal .NET 8 usage changes by @filmor in pythonnet/pythonnet#2634 * Drop performance tests by @filmor in pythonnet/pythonnet#2636 * Properly detect availability of BinaryFormatter by @filmor in pythonnet/pythonnet#2639 * Use last compiler toolset version that support .NET 8 by @filmor in pythonnet/pythonnet#2640 * Add dependabot file by @filmor in pythonnet/pythonnet#2642 * Use official ARM runners by @filmor in pythonnet/pythonnet#2641 * Bump actions/upload-pages-artifact from 3 to 4 by @dependabot[bot] in pythonnet/pythonnet#2644 * Bump actions/setup-python from 2 to 6 by @dependabot[bot] in pythonnet/pythonnet#2646 * Bump actions/checkout from 2 to 5 by @dependabot[bot] in pythonnet/pythonnet#2648 * Bump actions/setup-dotnet from 1 to 5 by @dependabot[bot] in pythonnet/pythonnet#2645 * Use uv and derive as much as possible from the environment, if available by @filmor in pythonnet/pythonnet#2652 * Fixes for the uv CI by @filmor in pythonnet/pythonnet#2654 * Bump astral-sh/setup-uv from 6 to 7 by @dependabot[bot] in pythonnet/pythonnet#2656 * Bump actions/checkout from 5 to 6 by @dependabot[bot] in pythonnet/pythonnet#2663 * Ensure that the tests work even if BinaryFormatter is not available by @filmor in pythonnet/pythonnet#2638 * Bump NUnit3TestAdapter from 5.2.0 to 6.0.0 by @dependabot[bot] in pythonnet/pythonnet#2667 * Fix line endings by @filmor in pythonnet/pythonnet#2668 * Switch to .NET SDK 10 by @lostmsu in pythonnet/pythonnet#2684 * Python 3.14 by @filmor in pythonnet/pythonnet#2611 * CI Improvements by @filmor in pythonnet/pythonnet#2669 * Bump System.Reflection.Emit from 4.3.0 to 4.7.0 by @dependabot[bot] in pythonnet/pythonnet#2694 * Bump pytest from 9.0.2 to 9.0.3 in the uv group across 1 directory by @dependabot[bot] in pythonnet/pythonnet#2705 * CI Improvements by @filmor in pythonnet/pythonnet#2707 * Fix method memleak test by @filmor in pythonnet/pythonnet#2708 * Bump actions/upload-pages-artifact from 4 to 5 by @dependabot[bot] in pythonnet/pythonnet#2709 * Update furo requirement from >=2022.9.15 to >=2025.12.19 by @dependabot[bot] in pythonnet/pythonnet#2711 * Move documentation deps to pyproject.toml by @filmor in pythonnet/pythonnet#2714 * Support .NET Framework 4.6.1 by @Metadorius in pythonnet/pythonnet#2701 * Fix wheel tags by @filmor in pythonnet/pythonnet#2716 * Name missing from __all__ on re-import by @filmor in pythonnet/pythonnet#2717 * Add context manager protocol for .NET IDisposable types by @den-run-ai in pythonnet/pythonnet#2568 * Fix MethodBinding/OverloadMapper memory leak (#691) by @greateggsgreg in pythonnet/pythonnet#2719 * Bump urllib3 from 2.6.3 to 2.7.0 in the uv group across 1 directory by @dependabot[bot] in pythonnet/pythonnet#2723 * Update NUnit by @filmor in pythonnet/pythonnet#2724 * Silence compile-time warnings by @filmor in pythonnet/pythonnet#2725 * Implement support for DLR get/set by @filmor in pythonnet/pythonnet#2706 * Bump idna from 3.13 to 3.15 in the uv group across 1 directory by @dependabot[bot] in pythonnet/pythonnet#2726 ## New Contributors * @RobPasMue made their first contribution in pythonnet/pythonnet#2542 * @dependabot[bot] made their first contribution in pythonnet/pythonnet#2644 * @Metadorius made their first contribution in pythonnet/pythonnet#2701 **Full Changelog**: pythonnet/pythonnet@v3.0.5...v3.1.0 ## 3.1.0-rc1 ## What's Changed * CI Improvements by @filmor in pythonnet/pythonnet#2669 * Bump System.Reflection.Emit from 4.3.0 to 4.7.0 by @dependabot[bot] in pythonnet/pythonnet#2694 * Bump pytest from 9.0.2 to 9.0.3 in the uv group across 1 directory by @dependabot[bot] in pythonnet/pythonnet#2705 * CI Improvements by @filmor in pythonnet/pythonnet#2707 * Fix method memleak test by @filmor in pythonnet/pythonnet#2708 * Bump actions/upload-pages-artifact from 4 to 5 by @dependabot[bot] in pythonnet/pythonnet#2709 * Update furo requirement from >=2022.9.15 to >=2025.12.19 by @dependabot[bot] in pythonnet/pythonnet#2711 * Move documentation deps to pyproject.toml by @filmor in pythonnet/pythonnet#2714 * Support .NET Framework 4.6.1 by @Metadorius in pythonnet/pythonnet#2701 * Fix wheel tags by @filmor in pythonnet/pythonnet#2716 * Name missing from __all__ on re-import by @filmor in pythonnet/pythonnet#2717 * Add context manager protocol for .NET IDisposable types by @den-run-ai in pythonnet/pythonnet#2568 * Fix MethodBinding/OverloadMapper memory leak (#691) by @greateggsgreg in pythonnet/pythonnet#2719 * Bump urllib3 from 2.6.3 to 2.7.0 in the uv group across 1 directory by @dependabot[bot] in pythonnet/pythonnet#2723 * Update NUnit by @filmor in pythonnet/pythonnet#2724 * Silence compile-time warnings by @filmor in pythonnet/pythonnet#2725 * Implement support for DLR get/set by @filmor in pythonnet/pythonnet#2706 ## New Contributors * @Metadorius made their first contribution in pythonnet/pythonnet#2701 **Full Changelog**: pythonnet/pythonnet@v3.1.0-rc0...v3.1.0-rc1 ## 3.1.0-rc0 ## What's Changed * ci: properly exclude job by @RobPasMue in pythonnet/pythonnet#2542 * `__delitem__` for `IList<T>` and `IDictionary<K,V>` by @lostmsu in pythonnet/pythonnet#2533 * Fix docs workflow by @filmor in pythonnet/pythonnet#2584 * Drop EOLd Python versions by @filmor in pythonnet/pythonnet#2632 * Bump setuptools and adjust license information by @filmor in pythonnet/pythonnet#2633 * Minimal .NET 8 usage changes by @filmor in pythonnet/pythonnet#2634 * Drop performance tests by @filmor in pythonnet/pythonnet#2636 * Properly detect availability of BinaryFormatter by @filmor in pythonnet/pythonnet#2639 * Use last compiler toolset version that support .NET 8 by @filmor in pythonnet/pythonnet#2640 * Add dependabot file by @filmor in pythonnet/pythonnet#2642 * Use official ARM runners by @filmor in pythonnet/pythonnet#2641 * Use uv and derive as much as possible from the environment, if available by @filmor in pythonnet/pythonnet#2652 * Fixes for the uv CI by @filmor in pythonnet/pythonnet#2654 * Ensure that the tests work even if BinaryFormatter is not available by @filmor in pythonnet/pythonnet#2638 * Fix line endings by @filmor in pythonnet/pythonnet#2668 * Switch to .NET SDK 10 by @lostmsu in pythonnet/pythonnet#2684 * Python 3.14 by @filmor in pythonnet/pythonnet#2611 ## New Contributors * @RobPasMue made their first contribution in pythonnet/pythonnet#2542 * @dependabot[bot] made their first contribution in pythonnet/pythonnet#2644 **Full Changelog**: pythonnet/pythonnet@v3.0.5...v3.1.0-rc0 Commits viewable in [compare view](pythonnet/pythonnet@v3.0.5...v3.1.0). </details> [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>dependabot
Bot
mentioned this pull request May 25, 2026 🔼 NuGet: Bump pythonnet from 3.0.5 to 3.1.0 Kestrun/Kestrun#411 Open dependabot
Bot
mentioned this pull request Oct 10, 2026 Bump pythonnet from 3.0.5 to 3.2.1 baleti/revit-ballet#3 Open dependabot
Bot
mentioned this pull request Oct 28, 2026 build: Bump pythonnet from 3.0.5 to 3.2.1 akuro17/StockAnalyzer-OSS#89 Open dependabot
Bot
mentioned this pull request Nov 10, 2026 MINOR: [C#] Bump pythonnet from 3.0.4 to 3.2.1 sg-scale/arrow--apache-arrow-18.1.0#10 Open Sign up for free to join this conversation on GitHub . Already have an account? Sign in to comment