5

I'm really confused on why this is happening to me:

Python 3.7.1 (default, Nov  5 2018, 14:07:04) 
Type 'copyright', 'credits' or 'license' for more information
IPython 6.4.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: 10**3.5
ValueError: could not convert string to float: 3.5

Could someone shine a light? As you can see, this is a plain input – what I thought would be a float literal.

I've tried to take away the ipython complexity, and run in isolated mode, and but still:

python3 -I -c "float('3.5')"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ValueError: could not convert string to float: '3.5'

Is my python3.7 broken, is my understanding broken, or what am I looking at?

I ruled out encoding problems by putting shown code into a file and hexdumping that. It's clean ascii, as it should be, with a 0x2e for a dot, and a 0x0a as a line ending:

xxd testfile.py
00000000: 332e 350a                                3.5.
python3 -I testfile.py
ValueError: could not convert string to float: 3.5

OS: Fedora 29 on an x86_64 with 16 GB of RAM.

Marcus Müller
  • 34,677
  • 4
  • 53
  • 94
  • 1
    Interesting- i wonder what conditions are necessary to reproduce this? For me this works as normal without `ValueError` on Python 3.7.1 with Ipython 7.1.1 – Chris_Rands Jan 18 '19 at 18:37
  • 1
    What happens when you `type(10)` and `type(3.5)`? – r.ook Jan 18 '19 at 18:42
  • @Idlehands: same type error for 3.5; int for 10. – Marcus Müller Jan 18 '19 at 18:44
  • @Idlehands re: dot character: nope, thought of that too – Marcus Müller Jan 18 '19 at 18:44
  • @Chris_Rands I'm as surprised as you (Ipython is not among the requirements, see the second listing)! – Marcus Müller Jan 18 '19 at 18:45
  • 3
    What about `import dis; dis.dis('3.5')`? – user2357112 Jan 18 '19 at 18:45
  • why 3.5 here is taken as string ? as per error – sahasrara62 Jan 18 '19 at 18:46
  • @Idlehands hope the encoding settings are ruled out -E, and I did try with the same code from a file, so keyboard shouldn't matter; checked twice: `0x2e` is the ascii-code for the classical full stop. – Marcus Müller Jan 18 '19 at 18:52
  • @Idlehands UTF encoding works fine, things like `os.getcwd()` work fine. – Marcus Müller Jan 18 '19 at 18:58
  • @user2357112: ```Traceback (most recent call last): File "", line 1, in File "/usr/lib64/python3.7/dis.py", line 74, in dis _disassemble_str(x, file=file, depth=depth) File "/usr/lib64/python3.7/dis.py", line 402, in _disassemble_str _disassemble_recursive(_try_compile(source, ''), **kwargs) File "/usr/lib64/python3.7/dis.py", line 29, in _try_compile c = compile(source, name, 'eval') ValueError: could not convert string to float: 3.5 ``` – Marcus Müller Jan 18 '19 at 18:58
  • Huh. An error at the `compile` call? That suggests a much lower-level problem than anything I was expecting. – user2357112 Jan 18 '19 at 19:01
  • How much free memory your machine has :))? Also is it a 32bit or 64 what OS? what's the result of `list(map(ord, '3.5'))`? – Mazdak Jan 18 '19 at 19:11
  • 1
    I don't think we're going to figure this one out without going through something like an instruction-level GDB session, which isn't something it's practical to carry out over Stack Overflow. The most practical option at this point might be to reinstall Python and hope the problem goes away. (This is reminding me of [that one time](https://stackoverflow.com/questions/45871269/why-can-10f-decimalu-emit-a-string-with-a-literal-colon) someone on AIX was seeing colons in the output of float-to-string conversion.) – user2357112 Jan 18 '19 at 19:13
  • What OS is this? Did you try restarting? I'm not educated enough but perhaps something went wrong when python 3.7.1 was compiled (if you compiled it on your machine). – r.ook Jan 18 '19 at 19:14
  • @Kasrâmvd: I can launch new tabs in a browser. Mallocing enough to parse a single line of python shouldn't be a problem. (64 bit, I'll be back with free memory in a minute) – Marcus Müller Jan 18 '19 at 19:32
  • @Idlehands adding that info to the question. Didn't compile myself. – Marcus Müller Jan 18 '19 at 19:33
  • 1
    @user2357112 I was already debugging things in GDB; turns out: I must have missed a `glibc` update happening under my eyes. The way libc functions were called made no sense. So, I restarted.. And lo, it worked – Marcus Müller Jan 18 '19 at 19:42
  • @Idlehands sadly I saw your comment too late: yeah, it was probably an unnoticed libc update. I'm confused how that would've happened (I normally know when I update core libraries... it's not like I run `dnf update` randomly), but I'm sorry I didn't notice earlier. Will now close, since non-reproducible. – Marcus Müller Jan 18 '19 at 19:44
  • Instead of deleting, decided to vote to close my own question. and then decided to answer it instead, as that is really a surprising place to notice a libc progression. – Marcus Müller Jan 18 '19 at 19:46

1 Answers1

1

The problem was caused by Fedora seemingly doing a glibc update without my interaction.

An extensiver-than-should-have-been investigation with GDB revealed that libc functionality was being called incorrectly.

So I rebooted. Problem seems solved.

Marcus Müller
  • 34,677
  • 4
  • 53
  • 94