New Features of Python 3.10:
- What usually included in a new minor version of Python?
- Python 3.10
-- Patterns matching statement (PEP634)
-- Enabling parentheses usage in with statement
- Python 3.9
-- Union operator on dictionary data type
- Thoughts on the development of the Python language
2. http://axonmatics.com
http://axonmatics.com
About me
- I develop software in Python roughly for 15 years and I train/consult
Python developers for 8 years
- I did research on formally specifying programming languages, prove
correctness of software systems, and building compilers
- I worked mainly on bio-/cheminformatic software development and
this topic also generally interests me (I have degree on medicine
development too)
Copyright (C) 2022 Dr. Guta Gábor
3. http://axonmatics.com
http://axonmatics.com
Agenda
- What usually included in a new minor version of Python?
- Python 3.10
- Patterns matching statement (PEP634)
- Enabling parentheses usage in with statement
- Python 3.9
- Union operator on dictionary data type
- Thoughts on the development of the Python language
Copyright (C) 2022 Dr. Guta Gábor
4. http://axonmatics.com
What is included in new release?
3.10 Release note
Source: https://docs.python.org/3/whatsnew/3.10.html
Copyright (C) 2022 Dr. Guta Gábor
5. http://axonmatics.com
http://axonmatics.com
PEP634 - base structure
a_num = int(input("Specify a number between 1 and 10:"))
match a_num:
case 1:
print('The smallest number')
case 2:
print('The first even number')
case 4|6|8|10:
print('An even number')
case _:
print('Out of range')
Copyright (C) 2022 Dr. Guta Gábor
6. http://axonmatics.com
http://axonmatics.com
PEP634 - variables and guard conditions
a_num = int(input("Specify a number between 1 and 10:"))
match a_num:
case 1:
print('The smallest number')
case x if x % 2 == 0:
print(f'{x} is an even number')
case x if x % 2 == 1:
print(f'{x} is an odd number')
Copyright (C) 2022 Dr. Guta Gábor
7. http://axonmatics.com
http://axonmatics.com
PEP634 - matching objects
class Duck:
__match_args__ = ("name",
"sound")
def __init__(self,
name,
sound):
self.name = name
self.sound = sound
def quack(self):
print(self.sound)
k = Duck('Donald', 'quaaaack')
k.name = input('Its name?')
k.sound = input('What does it say?')
match k:
case Duck('Duck', sound):
print('Please, provide a ' +
'name for the duck?')
case Duck(name, sound):
print(f'{name} says {sound}')
Copyright (C) 2022 Dr. Guta Gábor
8. http://axonmatics.com
http://axonmatics.com
PEP634 - matching lists and dictionaries
k = ['Donald', 'Quack']
k[0] = input('Its name?')
k[1] = ('What does it say?')
match k:
case ['Duck', sound]:
print('Please, provide ' +
'a name for the duck?')
case [name, sound]:
print(f'{name} says ' +
f'{sound}')
k = {'name': 'Donald',
'sound': 'Quack'}
k['name'] = input('Its name?')
k['sound'] = ('What does it say?')
match k:
case {'name': 'Duck',
'sound': sound}:
print('Please, provide ' +
'a name for the duck?')
case {'name': name,
'sound': sound}:
print(f'{name} says {sound}')
Copyright (C) 2022 Dr. Guta Gábor
11. http://axonmatics.com
http://axonmatics.com
Release cycles
• Currently, there is a new version in every year
• Security fixes provided up to 5 years and
1.5 years is the general support cycle
• My personal experience is that approx. 0.5-1 year
is needed to new version become widely adapted
(e.g. Anaconda, AWS lambda, etc.)
• See PEP602 for further details
Verzió Kiadási dátum
3.0 2008/12
3.1 2009/06
2.7 2010/07
3.2 2011/02
... ...
3.7 2018/06
3.8 2019/10
3.9 2020/10
3.10 2021/10
3.11 2022/10
Copyright (C) 2022 Dr. Guta Gábor
12. http://axonmatics.com
Development of the Python language
● Within 5-8 years needed for new language element to completely change
or to become fully accepted:
○ Asynchronous language constructs:
generator-based coroutine vs. native coroutine
○ Type annotations (type hints)
● Regular small changes
○ Walrus operator in version 3.8 (:=)
● Important internal changes
○ New PEG (Parsing Expression Grammar) parser in version 3.9
Copyright (C) 2022 Dr. Guta Gábor
13. http://axonmatics.com
Version Changes of the asynchronous language constructs
3.4 • PEP 3156, a new "asyncio" module, a new framework for asynchronous I/O
3.5 • PEP 492, coroutines with async and await syntax
3.6 • PEP 525, Asynchronous Generators (provisional)
• PEP 530, Asynchronous Comprehensions
3.7 • Backwards incompatible syntax changes: async and await are now reserved keywords.
• The asyncio module has received new features, significant usability and performance improvements.
3.8 • asyncio.run() has graduated from the provisional to stable API.
• Running python -m asyncio launches a natively async REPL.
• Several other changes in asyncio package
3.9 • Parallel running of aclose() / asend() / athrow() is now prohibited, and ag_running now reflects the actual
running status of the async generator. (Contributed by Yury Selivanov in bpo-30773.)
• Several other changes in asyncio package
3.10 • Two new builtin functions – aiter() and anext() have been added to provide asynchronous counterparts to
iter() and next(), respectively. (Contributed by Joshua Bronson, Daniel Pope, and Justin Wang in
bpo-31861.)
Copyright (C) 2022 Dr. Guta Gábor