11
davide
1y

Well... this is to demonstrate that GPT is not smart as most of people think. There is no coalescing operator in python

Comments
  • 9
    This is a good example of how AI's are working. They don't know shit. They just look-up in the data.

    And yes, if the bot was trained with this information : https://peps.python.org/pep-0505/

    then it will assume that the information is correct.

    It doesn't know that the article was a draft and that it never made into the language.
  • 2
    @Grumm I think it is not that it considered PEP505 to arrive at such answer. First of all, GPT assumes that the user is always right. This means that if the user tells him to use null coalescing with python, he assumes that this feature exists. With the knowledge he has of other languages, he creates this syntax and makes it Python-compatible. The problem is that a newbie might waste a lot of time with this kind of error simply because he puts full trust in the AI and assumes that its answers are always right. Surely this will be improved in the future (perhaps already with GPT4 the output is different) but until then I prefer to consult the old stackoverflow
  • 4
    There definitely should be coalescing and coalescing assignment operators though!
  • 2
    My question is much more: Why did it not make into the language? For me it seems like a nice feature.
  • 1
    @happygimp0 In the link I posted they explain why it was rejected :

    Similar behavior to the ?? operator can be achieved with an or expression, however or checks whether its left operand is false-y and not specifically None. This approach is attractive, as it requires fewer changes to the language, but ultimately does not solve the underlying problem correctly.

    So it is just based on 'we already have a thing that does it'.
  • 0
    @davide uhmm I still think that since it is a language model AI, it doesn't know what is true or false if the AI finds relevant information about the subject.

    It just search for already known statements. Like a query send to the API and will make a 'human answer' from the result.

    But doing that it will also make 'hypothetical' versions.

    Using this for just programming without any thinking is wrong. Even with the next version.
  • 1
    So I decided to see if python has an operator than can do this.

    It does: other = s or "some default value"

    Wait what?! Yes, I was shocked too. Explanation in link.

    https://stackoverflow.com/questions...
  • 0
    @Oktokolo I found one, see my previous comment.
  • 2
    @Demolishun A true None coalescing operator works for maybe booleans too. But i also totally forgot about the "or" trick (which also has been used in PHP before it got its coalescing operator).
  • 1
    Aw this seems to have been fixed, I lost a valuable piece to make fun of ChatGPT with
  • 2
    @SalsaGal Don't worry, just ask chatgpt how to do something what's impossible or obscure it will always explain a non-existenting solution confidently
  • 2
    @Demolishun That's a completely different thing. As stated in the linked answer

    42 or "something" # returns 42

    0 or "something" # returns "something"

    None or "something" # returns "something"

    False or "something" # returns "something"

    "" or "something" # returns "something"

    This is not what coalescing operator is. Coalescing operator should behave like

    42 ?? "something" # returns 42

    0 ?? "something" # returns 0

    None ?? "something" # returns "something"

    False ?? "something" # returns False

    "" ?? "something" # returns ""
  • 0
    @hitko I use it for null in JS. So the or from Python would work for what I need.

    This would be poor mans coalescing operator for Python.
Add Comment