Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for The Python 3.1 problem
Hugo van Kemenade
Hugo van Kemenade

Posted on • Edited on

     

The Python 3.1 problem

Moved tohttps://hugovk.dev/blog/2021/the-python-3-1-problem/

Or, a variation on the Norway problem

Short version: put quotes around version numbers in YAML.

The Norway problem

TheNorway problem is when you put this in YAML:

countries:-GB-IE-FR-DE-NO
Enter fullscreen modeExit fullscreen mode

But get this out:

>>>importyaml>>>withopen("countries.yml")asf:...yaml.safe_load(f)...{'countries':['GB','IE','FR','DE',False]}
Enter fullscreen modeExit fullscreen mode

😱

The Norway fix

Use quotes:

countries:-"GB"-"IE"-"FR"-"DE"-"NO"
Enter fullscreen modeExit fullscreen mode
>>>withopen("countries.yml")asf:...yaml.safe_load(f)...{'countries':['GB','IE','FR','DE','NO']}
Enter fullscreen modeExit fullscreen mode

🇳🇴 ✅

The Python 3.1 problem

A similar problem will affect the Python community in October 2021, whenPython 3.10 comes out.

Why?

When3.10 is added to YAML, for example in CI test matrix config, it's interpreted as a float. This:

python-version:[3.6,3.7,3.8,3.9,3.10,pypy3,]
Enter fullscreen modeExit fullscreen mode

Turns into this:

>>>importyaml>>>withopen("versions.yml")asf:...yaml.safe_load(f)...{'python-version':[3.6,3.7,3.8,3.9,3.1,'pypy3']}
Enter fullscreen modeExit fullscreen mode

CI failed! It's not2009! Python 3.1 not found!

😱

Relatedly,3.10-dev without quotes works because it's interpreted as a string. But when deleting-dev,3.10 is interpreted as a float.

The Python 3.10 fix

Version numbers are strings, not floats. Use quotes:

python-version:["3.6","3.7","3.8","3.9","3.10","pypy3",]
Enter fullscreen modeExit fullscreen mode
>>>importyaml>>>withopen("versions.yml")asf:...yaml.safe_load(f)...{'python-version':['3.6','3.7','3.8','3.9','3.10','pypy3']}
Enter fullscreen modeExit fullscreen mode

🐍 ✅

See also

flake8-2020 is a useful Flake8 plugin to find Python 3.10 and other bugs caused by assumptions about the length of version numbers when usingsys.version andsys.version_info.


Header photo: "zero" byLeo Reynolds is licensed underCC BY-NC-SA 2.0.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Python 3.14 & 3.15 release manager, core developer, PSF Fellow, open-source maintainer, PEP editor, NaNoGenMo organiser
  • Location
    Helsinki, Finland
  • Joined

More fromHugo van Kemenade

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp