Git Product home page Git Product logo

Comments (2)

almann avatar almann commented on June 2, 2024

My recollection of this (and it has been a long time), has to do with sub-typing True and False, which Python doesn't let you do (see this thread). IIRC, we have this problem with None as well.

That said, a potential solution here is, in the non-annotated case (where the Boolean value has no additional Ion value type meta-data like annotations), we could potentially use the non-Ion type there. I'd have to dig into this a bit deeper, to make sure this doesn't break anything, but I think it could work at the cost of a slight bit more complexity.

from ion-python.

rmarrowstone avatar rmarrowstone commented on June 2, 2024

A different user recently asked about this behavior and it prompted me to dig a bit. Here's what I found.

I don't believe that the type of the values in memory are incorrect. I do believe that the behavior is confusing for users, because the __repr__ is confusing and the type() is misleading.

Consider:

>>> b = simpleion.loads('true')
>>> b
1
>>> type(b)
<class 'amazon.ion.simple_types.IonPyInt'>
>>> b.ion_type
<IonType.BOOL: 1>
>>> simpleion.dumps(b, binary=False)
'$ion_1_0 true'

So we can see that simpleion does correctly roundtrip the value and that the ion_type is correct.

Another confusion is with default equality, though ion_equals() is correct:

>>> from amazon.ion import simpleion
>>> from amazon.ion.equivalence import ion_equals
>>> i = simpleion.loads('1')
>>> b = simpleion.loads('true')
>>> i == b
True <--- seems wrong, but actually 1 == True in python
>>> ion_equals(i, b)
False

from ion-python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.