Skip to content

Nullable<Decimal> comparisons  #2527

Description

@briandesarmo

Environment

  • Pythonnet version: 3.0.3
  • Python version: 3.12
  • Operating System: Windows
  • .NET Runtime: 4.8

Details

  • Describe what you were trying to get done.

We have python embedded in C# and are putting into scope objects that have Nullable<Decimal> properties and running (user provided python) code which tests for null(None). This fails when the property has a value and we compare the value to None using the == and != operators. It appears to work when we use the pythonic syntax not x or x is not None. We have upgraded from 2.5.2 to 3.0.3, also went from from Python 3.8 to 3.12. This code worked in previous versions.

## This does not work
x = None
print(x == None)
x = System.Decimal(1.23)
print(x == None)

## This works
x = None
print(not x)
x = System.Decimal(1.23)
print(not x)

## This also works
x = None
print(x is not None)
x = System.Decimal(1.23)
print(x is not None)
  • If there was a crash, please include the traceback here.
True
No method matches given arguments for Decimal.op_Equality: (<class 'NoneType'>)   File "<string>", line 5, in <module>

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions