GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Python exception raised on conversion failure by macaronikazoo · Pull Request #2741 · pythonnet/pythonnet

Conversation

@macaronikazoo

@macaronikazoo macaronikazoo commented Sep 24, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

What does this implement/fix? Explain your changes.

Converting a CLR value to Python can throw after the call has succeeded, eg if an encoder's TryEncode throws, or if calling enumerator.Current throws. Previously the exception was never converted to a Python exception making it uncatchable even instead, so Python code could not catch it, not even using except BaseException

  • MethodBinder.Invoke guarded only the invocation, and converted the result and out parameters after its try/catch
  • Iterator.tp_iternext guarded MoveNext but not Current or the conversion of the item
  • ArrayObject indexing converted items with no guard at all

Each now reports the failure through Exceptions.SetError, as the existing catch already does for the call itself. Property and field getters already convert inside their try and are unchanged.

Checklist

Check all those that are applicable and complete.

  • Make sure to include one or more tests for your change
  • [n/a] If an enhancement PR, please create docs and at best an example
  • Ensure you have signed the .NET Foundation CLA

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@macaronikazoo
Python exception raised on conversion failure
2fe63b5
Converting a CLR value to Python can throw after the call has
succeeded, eg if an encoder's TryEncode throws, or if calling
enumerator.Current throws. Previously the exception was never
converted to a Python exception making it uncatchable even
instead, so Python code could not catch it, not even using
except BaseException

- MethodBinder.Invoke guarded only the invocation, and converted the
  result and out parameters after its try/catch
- Iterator.tp_iternext guarded MoveNext but not Current or the
  conversion of the item
- ArrayObject indexing converted items with no guard at all

Each now reports the failure through Exceptions.SetError, as the
existing catch already does for the call itself. Property and field
getters already convert inside their try and are unchanged.
@filmor

filmor commented Sep 24, 2026

Copy link
Copy Markdown
Member

Thanks a lot. If all is well, I will merge this and release an rc2 today.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@macaronikazoo

macaronikazoo commented Sep 24, 2026

Copy link
Copy Markdown
Contributor Author

ok no worries - I have another one that I'll create shortly... related to disallowing certain .net types to be handed over to python

filmor reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@macaronikazoo

macaronikazoo commented Sep 24, 2026

Copy link
Copy Markdown
Contributor Author

however, the other change I want to submit builds off this one - but this one seemed useful in an of itself, so I submitted it separately. should I wait for this one to be accepted before submitting the other PR?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@filmor

filmor commented Sep 24, 2026

Copy link
Copy Markdown
Member

Just go ahead. I won't have time before afternoon for a proper review.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

filmor
filmor approved these changes Sep 25, 2026
View reviewed changes
@filmor
filmor merged commit a7af7a8 into pythonnet:master Sep 25, 2026
36 checks passed

Uh oh!

There was an error while loading. Please reload this page.

This was referenced Oct 4, 2026
Bump pythonnet from 3.1.0 to 3.2.0 zcsizmadia/PyDotNet#130
Closed
chore: Bump pythonnet from 3.1.0 to 3.2.0 apache/arrow-dotnet#456
Closed
deps: Bump pythonnet from 3.1.0 to 3.2.0 aj-geddes/revitpy#23
Closed
Bump pythonnet from 3.0.5 to 3.2.1 baleti/revit-ballet#3
Open
This was referenced Oct 11, 2026
Bump pythonnet from 3.1.0 to 3.2.1 zcsizmadia/PyDotNet#133
Merged
deps: Bump pythonnet from 3.1.0 to 3.2.1 aj-geddes/revitpy#31
Open
@lostmsu

lostmsu commented Oct 14, 2026

Copy link
Copy Markdown
Member

This is not the right fix for the issue as it spreads to other paths.

There's only one call site for TryEncode:

pythonnet/src/runtime/Converter.cs

Line 135 in 89170a4

var encoded = PyObjectConversions.TryEncode(value, type);

Why wasn't it modified?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dependabot 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
@eirannejad eirannejad mentioned this pull request Nov 9, 2026
Ein/9.x/pythonnet 3.2.1 mcneel/pythonnet#6
Merged
@dependabot 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

Reviewers

@filmor filmor filmor approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@macaronikazoo @filmor @lostmsu
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.