SlideShare a Scribd company logo
Python 3.8
Henry Schreiner
October 18, 2019
New in Python
• Python 3.6
▶ Big update
▶ First version fast as 2.7
▶ New f-strings very popular
• Python 3.7
▶ First version faster than 2.7
▶ OpenSSL update has affected adoption
• Python 3.8
▶ Released just a few days ago!
▶ What’s new?
1/13Henry Schreiner Python 3.8 October 18, 2019
Themes
• Performance
• ABI / Internals
• Static typing
2/13Henry Schreiner Python 3.8 October 18, 2019
Python 3.8: Positional-only arguments
d = dict(one=1, two=2)
d = dict({'one':1, 'two':2}
Challenge: write dict yourself
3/13Henry Schreiner Python 3.8 October 18, 2019
Python 3.8: Positional-only arguments
d = dict(one=1, two=2)
d = dict({'one':1, 'two':2}
Challenge: write dict yourself
def dict(arg=None, **kargs):
...
dict(arg=3) # OOPS!
You have to use *args, and limit to 1 arg yourself. Or…
3/13Henry Schreiner Python 3.8 October 18, 2019
Python 3.8: Positional-only arguments (2)
If you look at the signatures of dict, pow, or some other builtins, you will see something kind of
like this:
def dict(arg=None, /, **kargs):
...
That is now valid Python in 3.8!
Why is it useful?
• Allow kwargs and positional arguments without overlap
• Force positional arguments without names
• You can change the internal name - not part of your API
def f(pos, /, pos_or_kw, *, kw_required, kw_optional=None):
...
4/13Henry Schreiner Python 3.8 October 18, 2019
Python 3.8: Walrus operator
Assignment in Python is a statement (limited):
item = ... # simple
item[...] = ... # item
item.attr = ... # attr
a, b, = ... # tuple
a = b = ... # chained (special case)
But what about assigning in other places, like in the C languages?
if x = True: # Will never be allowed, too easy to make mistake
f(x=True) # Keyword argument
5/13Henry Schreiner Python 3.8 October 18, 2019
Python 3.8: Walrus operator (2)
Solution: A new operator!
• Spelling: := (looks like a sideways walrus)
• Works almost anywhere normal = doesn’t (one way to do things)
• Often requires parenthesis for clarity
if res := check():
print(res)
a = [None, 0, 1, 2]
while a := b.pop():
print(a)
• Use carefully: could make code harder to read
• C++17/C++20 adding variable defines in loops for similar reasons
• Scope leaks, (un?)fortunately
6/13Henry Schreiner Python 3.8 October 18, 2019
Python 3.8: f-string debugging
In Python 3.6, f-strings make string interpolation easy:
>>> x = 3
>>> print(f"x = {x}")
x = 3
Debugging is now DRY with the = specifier:
>>> print(f"{x = }")
x = 3
• Spaces respected
• Mix with complex expressions or formatting
7/13Henry Schreiner Python 3.8 October 18, 2019
Python 3.8: Static typing
Static type hints are a big feature of Python 3, and now they are much more powerful:
Literals type (AKA make-shift enums)
def f(val : Literal['yes', 'no', 'auto']): ...
Final (AKA const)
x : Final[bool] = True
x = False # Invalid in type checker like mypy
Protocols (ACA C++20 Concepts / Java Interface)
class HasName(Protocol):
name: str
Now you can use HasName, will require a name attribute.
8/13Henry Schreiner Python 3.8 October 18, 2019
TypedASDT
• TypedAST merged into Python!
• feature_version selector (3.4+)
>>> import ast
>>> s = ast.parse('x = 2 # type: Int', type_comments=True)
>>> ast.dump(s)
"Module(body=[Assign(
targets=[Name(id='x', ctx=Store())],
value=Constant(value=2, kind=None),
type_comment='Int')],
type_ignores=[])"
• ast.get_source_segment gets the source for a bit of ast, if location information is
present.
9/13Henry Schreiner Python 3.8 October 18, 2019
Other features
• TypedDict gives types to dict parts
• importlib.metadata gives you info from installed packages (like importlib.resources)
• math and statistics have new functions
• namedtuple, pickle, and more are faster
• SyntaxError messages are more detailed in some common cases
• multiprocessing.shared_memory – can avoid pickle transfer of objects
• reversed works on dicts
• Unpacking in return/yield
10/13Henry Schreiner Python 3.8 October 18, 2019
Other developer changes
• --libs no longer include libpython
• Single ABI for debug/release
• Runtime audit hooks
• New C API for initialization
• Provisional vectorcall protocol – fast calling of C functions
• Pickle support out-of-band data (multiple streams) (Protocol 5)
• __code__ now has .replace, like __signature__
11/13Henry Schreiner Python 3.8 October 18, 2019
Final Words
Released
• Python.org released
• Docker: docker run --rm -it python:3.8
• Scikit-HEP GCC 9.2 ManyLinux1 containers
Not yet released
• Conda: Coming soon
• Numpy wheels
• Homebrew: In progress
• Still missing in Azure, etc.
• Scikit-HEP build tools (Windows, ManyLinux1 + GCC 9.2)
12/13Henry Schreiner Python 3.8 October 18, 2019
Sources
• Official docs
• RealPython article
• DeepSource
This presentation available at /henryiii/python38.
13/13Henry Schreiner Python 3.8 October 18, 2019

More Related Content

What's hot

DIANA: Recent developments in GooFit
DIANA: Recent developments in GooFitDIANA: Recent developments in GooFit
DIANA: Recent developments in GooFit
Henry Schreiner
 
Pybind11 - SciPy 2021
Pybind11 - SciPy 2021Pybind11 - SciPy 2021
Pybind11 - SciPy 2021
Henry Schreiner
 
CHEP 2018: A Python upgrade to the GooFit package for parallel fitting
CHEP 2018: A Python upgrade to the GooFit package for parallel fittingCHEP 2018: A Python upgrade to the GooFit package for parallel fitting
CHEP 2018: A Python upgrade to the GooFit package for parallel fitting
Henry Schreiner
 
ROOT 2018: iminuit and MINUIT2 Standalone
ROOT 2018: iminuit and MINUIT2 StandaloneROOT 2018: iminuit and MINUIT2 Standalone
ROOT 2018: iminuit and MINUIT2 Standalone
Henry Schreiner
 
PyHEP 2018: Tools to bind to Python
PyHEP 2018:  Tools to bind to PythonPyHEP 2018:  Tools to bind to Python
PyHEP 2018: Tools to bind to Python
Henry Schreiner
 
ACAT 2017: GooFit 2.0
ACAT 2017: GooFit 2.0ACAT 2017: GooFit 2.0
ACAT 2017: GooFit 2.0
Henry Schreiner
 
PEARC17: Modernizing GooFit: A Case Study
PEARC17: Modernizing GooFit: A Case StudyPEARC17: Modernizing GooFit: A Case Study
PEARC17: Modernizing GooFit: A Case Study
Henry Schreiner
 
HOW 2019: A complete reproducible ROOT environment in under 5 minutes
HOW 2019: A complete reproducible ROOT environment in under 5 minutesHOW 2019: A complete reproducible ROOT environment in under 5 minutes
HOW 2019: A complete reproducible ROOT environment in under 5 minutes
Henry Schreiner
 
2019 IRIS-HEP AS workshop: Particles and decays
2019 IRIS-HEP AS workshop: Particles and decays2019 IRIS-HEP AS workshop: Particles and decays
2019 IRIS-HEP AS workshop: Particles and decays
Henry Schreiner
 
RDM 2020: Python, Numpy, and Pandas
RDM 2020: Python, Numpy, and PandasRDM 2020: Python, Numpy, and Pandas
RDM 2020: Python, Numpy, and Pandas
Henry Schreiner
 
Pypy is-it-ready-for-production-the-sequel
Pypy is-it-ready-for-production-the-sequelPypy is-it-ready-for-production-the-sequel
Pypy is-it-ready-for-production-the-sequel
Mark Rees
 
PyPy - is it ready for production
PyPy - is it ready for productionPyPy - is it ready for production
PyPy - is it ready for production
Mark Rees
 
carrow - Go bindings to Apache Arrow via C++-API
carrow - Go bindings to Apache Arrow via C++-APIcarrow - Go bindings to Apache Arrow via C++-API
carrow - Go bindings to Apache Arrow via C++-API
Yoni Davidson
 
Pig: Data Analysis Tool in Cloud
Pig: Data Analysis Tool in Cloud Pig: Data Analysis Tool in Cloud
Pig: Data Analysis Tool in Cloud
Jianfeng Zhang
 
Reversing the dropbox client on windows
Reversing the dropbox client on windowsReversing the dropbox client on windows
Reversing the dropbox client on windows
extremecoders
 
Tensorflow internal
Tensorflow internalTensorflow internal
Tensorflow internal
Hyunghun Cho
 
Move from C to Go
Move from C to GoMove from C to Go
Move from C to Go
Yu-Shuan Hsieh
 
Available HPC resources at CSUC
Available HPC resources at CSUCAvailable HPC resources at CSUC
Distributed Multi-device Execution of TensorFlow – an Outlook
Distributed Multi-device Execution of TensorFlow – an OutlookDistributed Multi-device Execution of TensorFlow – an Outlook
Distributed Multi-device Execution of TensorFlow – an OutlookSebnem Rusitschka
 
High Performance Python - Marc Garcia
High Performance Python - Marc GarciaHigh Performance Python - Marc Garcia
High Performance Python - Marc Garcia
Marc Garcia
 

What's hot (20)

DIANA: Recent developments in GooFit
DIANA: Recent developments in GooFitDIANA: Recent developments in GooFit
DIANA: Recent developments in GooFit
 
Pybind11 - SciPy 2021
Pybind11 - SciPy 2021Pybind11 - SciPy 2021
Pybind11 - SciPy 2021
 
CHEP 2018: A Python upgrade to the GooFit package for parallel fitting
CHEP 2018: A Python upgrade to the GooFit package for parallel fittingCHEP 2018: A Python upgrade to the GooFit package for parallel fitting
CHEP 2018: A Python upgrade to the GooFit package for parallel fitting
 
ROOT 2018: iminuit and MINUIT2 Standalone
ROOT 2018: iminuit and MINUIT2 StandaloneROOT 2018: iminuit and MINUIT2 Standalone
ROOT 2018: iminuit and MINUIT2 Standalone
 
PyHEP 2018: Tools to bind to Python
PyHEP 2018:  Tools to bind to PythonPyHEP 2018:  Tools to bind to Python
PyHEP 2018: Tools to bind to Python
 
ACAT 2017: GooFit 2.0
ACAT 2017: GooFit 2.0ACAT 2017: GooFit 2.0
ACAT 2017: GooFit 2.0
 
PEARC17: Modernizing GooFit: A Case Study
PEARC17: Modernizing GooFit: A Case StudyPEARC17: Modernizing GooFit: A Case Study
PEARC17: Modernizing GooFit: A Case Study
 
HOW 2019: A complete reproducible ROOT environment in under 5 minutes
HOW 2019: A complete reproducible ROOT environment in under 5 minutesHOW 2019: A complete reproducible ROOT environment in under 5 minutes
HOW 2019: A complete reproducible ROOT environment in under 5 minutes
 
2019 IRIS-HEP AS workshop: Particles and decays
2019 IRIS-HEP AS workshop: Particles and decays2019 IRIS-HEP AS workshop: Particles and decays
2019 IRIS-HEP AS workshop: Particles and decays
 
RDM 2020: Python, Numpy, and Pandas
RDM 2020: Python, Numpy, and PandasRDM 2020: Python, Numpy, and Pandas
RDM 2020: Python, Numpy, and Pandas
 
Pypy is-it-ready-for-production-the-sequel
Pypy is-it-ready-for-production-the-sequelPypy is-it-ready-for-production-the-sequel
Pypy is-it-ready-for-production-the-sequel
 
PyPy - is it ready for production
PyPy - is it ready for productionPyPy - is it ready for production
PyPy - is it ready for production
 
carrow - Go bindings to Apache Arrow via C++-API
carrow - Go bindings to Apache Arrow via C++-APIcarrow - Go bindings to Apache Arrow via C++-API
carrow - Go bindings to Apache Arrow via C++-API
 
Pig: Data Analysis Tool in Cloud
Pig: Data Analysis Tool in Cloud Pig: Data Analysis Tool in Cloud
Pig: Data Analysis Tool in Cloud
 
Reversing the dropbox client on windows
Reversing the dropbox client on windowsReversing the dropbox client on windows
Reversing the dropbox client on windows
 
Tensorflow internal
Tensorflow internalTensorflow internal
Tensorflow internal
 
Move from C to Go
Move from C to GoMove from C to Go
Move from C to Go
 
Available HPC resources at CSUC
Available HPC resources at CSUCAvailable HPC resources at CSUC
Available HPC resources at CSUC
 
Distributed Multi-device Execution of TensorFlow – an Outlook
Distributed Multi-device Execution of TensorFlow – an OutlookDistributed Multi-device Execution of TensorFlow – an Outlook
Distributed Multi-device Execution of TensorFlow – an Outlook
 
High Performance Python - Marc Garcia
High Performance Python - Marc GarciaHigh Performance Python - Marc Garcia
High Performance Python - Marc Garcia
 

Similar to PyHEP 2019: Python 3.8

Python Evolution
Python EvolutionPython Evolution
Python Evolution
Quintagroup
 
Intro to Python
Intro to PythonIntro to Python
Intro to Python
Daniel Greenfeld
 
Moving to Python 3
Moving to Python 3Moving to Python 3
Moving to Python 3
Nick Efford
 
Python Course Basic
Python Course BasicPython Course Basic
Python Course Basic
Naiyan Noor
 
Porting to Python 3
Porting to Python 3Porting to Python 3
Porting to Python 3
Lennart Regebro
 
Python scripting kick off
Python scripting kick offPython scripting kick off
Python scripting kick off
Andrea Gangemi
 
slides1-introduction to python-programming.pptx
slides1-introduction to python-programming.pptxslides1-introduction to python-programming.pptx
slides1-introduction to python-programming.pptx
AkhdanMumtaz
 
Python introduction towards data science
Python introduction towards data sciencePython introduction towards data science
Python introduction towards data science
deepak teja
 
What's new in Python 3.11
What's new in Python 3.11What's new in Python 3.11
What's new in Python 3.11
Henry Schreiner
 
See through C
See through CSee through C
See through C
Tushar B Kute
 
Python 3000
Python 3000Python 3000
Python 3000
Alexandro Colorado
 
Python PPT by Sushil Sir.pptx
Python PPT by Sushil Sir.pptxPython PPT by Sushil Sir.pptx
Python PPT by Sushil Sir.pptx
sushil155005
 
Porting to Python 3
Porting to Python 3Porting to Python 3
Porting to Python 3
Lennart Regebro
 
2018 cosup-delete unused python code safely - english
2018 cosup-delete unused python code safely - english2018 cosup-delete unused python code safely - english
2018 cosup-delete unused python code safely - english
Jen Yee Hong
 
Everything You Always Wanted to Know About Memory in Python But Were Afraid t...
Everything You Always Wanted to Know About Memory in Python But Were Afraid t...Everything You Always Wanted to Know About Memory in Python But Were Afraid t...
Everything You Always Wanted to Know About Memory in Python But Were Afraid t...
Piotr Przymus
 
A Gentle Introduction to Coding ... with Python
A Gentle Introduction to Coding ... with PythonA Gentle Introduction to Coding ... with Python
A Gentle Introduction to Coding ... with Python
Tariq Rashid
 
Enjoy Type Hints and its benefits
Enjoy Type Hints and its benefitsEnjoy Type Hints and its benefits
Enjoy Type Hints and its benefits
masahitojp
 
Lecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptxLecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptx
jovannyflex
 
Lecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptxLecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptx
jovannyflex
 

Similar to PyHEP 2019: Python 3.8 (20)

Python Evolution
Python EvolutionPython Evolution
Python Evolution
 
Intro
IntroIntro
Intro
 
Intro to Python
Intro to PythonIntro to Python
Intro to Python
 
Moving to Python 3
Moving to Python 3Moving to Python 3
Moving to Python 3
 
Python Course Basic
Python Course BasicPython Course Basic
Python Course Basic
 
Porting to Python 3
Porting to Python 3Porting to Python 3
Porting to Python 3
 
Python scripting kick off
Python scripting kick offPython scripting kick off
Python scripting kick off
 
slides1-introduction to python-programming.pptx
slides1-introduction to python-programming.pptxslides1-introduction to python-programming.pptx
slides1-introduction to python-programming.pptx
 
Python introduction towards data science
Python introduction towards data sciencePython introduction towards data science
Python introduction towards data science
 
What's new in Python 3.11
What's new in Python 3.11What's new in Python 3.11
What's new in Python 3.11
 
See through C
See through CSee through C
See through C
 
Python 3000
Python 3000Python 3000
Python 3000
 
Python PPT by Sushil Sir.pptx
Python PPT by Sushil Sir.pptxPython PPT by Sushil Sir.pptx
Python PPT by Sushil Sir.pptx
 
Porting to Python 3
Porting to Python 3Porting to Python 3
Porting to Python 3
 
2018 cosup-delete unused python code safely - english
2018 cosup-delete unused python code safely - english2018 cosup-delete unused python code safely - english
2018 cosup-delete unused python code safely - english
 
Everything You Always Wanted to Know About Memory in Python But Were Afraid t...
Everything You Always Wanted to Know About Memory in Python But Were Afraid t...Everything You Always Wanted to Know About Memory in Python But Were Afraid t...
Everything You Always Wanted to Know About Memory in Python But Were Afraid t...
 
A Gentle Introduction to Coding ... with Python
A Gentle Introduction to Coding ... with PythonA Gentle Introduction to Coding ... with Python
A Gentle Introduction to Coding ... with Python
 
Enjoy Type Hints and its benefits
Enjoy Type Hints and its benefitsEnjoy Type Hints and its benefits
Enjoy Type Hints and its benefits
 
Lecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptxLecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptx
 
Lecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptxLecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptx
 

More from Henry Schreiner

Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024
Henry Schreiner
 
Software Quality Assurance Tooling - Wintersession 2024
Software Quality Assurance Tooling - Wintersession 2024Software Quality Assurance Tooling - Wintersession 2024
Software Quality Assurance Tooling - Wintersession 2024
Henry Schreiner
 
Princeton RSE Peer network first meeting
Princeton RSE Peer network first meetingPrinceton RSE Peer network first meeting
Princeton RSE Peer network first meeting
Henry Schreiner
 
Software Quality Assurance Tooling 2023
Software Quality Assurance Tooling 2023Software Quality Assurance Tooling 2023
Software Quality Assurance Tooling 2023
Henry Schreiner
 
Princeton Wintersession: Software Quality Assurance Tooling
Princeton Wintersession: Software Quality Assurance ToolingPrinceton Wintersession: Software Quality Assurance Tooling
Princeton Wintersession: Software Quality Assurance Tooling
Henry Schreiner
 
Everything you didn't know you needed
Everything you didn't know you neededEverything you didn't know you needed
Everything you didn't know you needed
Henry Schreiner
 
SciPy22 - Building binary extensions with pybind11, scikit build, and cibuild...
SciPy22 - Building binary extensions with pybind11, scikit build, and cibuild...SciPy22 - Building binary extensions with pybind11, scikit build, and cibuild...
SciPy22 - Building binary extensions with pybind11, scikit build, and cibuild...
Henry Schreiner
 
SciPy 2022 Scikit-HEP
SciPy 2022 Scikit-HEPSciPy 2022 Scikit-HEP
SciPy 2022 Scikit-HEP
Henry Schreiner
 
PyCon 2022 -Scikit-HEP Developer Pages: Guidelines for modern packaging
PyCon 2022 -Scikit-HEP Developer Pages: Guidelines for modern packagingPyCon 2022 -Scikit-HEP Developer Pages: Guidelines for modern packaging
PyCon 2022 -Scikit-HEP Developer Pages: Guidelines for modern packaging
Henry Schreiner
 
PyCon2022 - Building Python Extensions
PyCon2022 - Building Python ExtensionsPyCon2022 - Building Python Extensions
PyCon2022 - Building Python Extensions
Henry Schreiner
 
boost-histogram / Hist: PyHEP Topical meeting
boost-histogram / Hist: PyHEP Topical meetingboost-histogram / Hist: PyHEP Topical meeting
boost-histogram / Hist: PyHEP Topical meeting
Henry Schreiner
 
HOW 2019: Machine Learning for the Primary Vertex Reconstruction
HOW 2019: Machine Learning for the Primary Vertex ReconstructionHOW 2019: Machine Learning for the Primary Vertex Reconstruction
HOW 2019: Machine Learning for the Primary Vertex Reconstruction
Henry Schreiner
 
ACAT 2019: A hybrid deep learning approach to vertexing
ACAT 2019: A hybrid deep learning approach to vertexingACAT 2019: A hybrid deep learning approach to vertexing
ACAT 2019: A hybrid deep learning approach to vertexing
Henry Schreiner
 
2019 CtD: A hybrid deep learning approach to vertexing
2019 CtD: A hybrid deep learning approach to vertexing2019 CtD: A hybrid deep learning approach to vertexing
2019 CtD: A hybrid deep learning approach to vertexing
Henry Schreiner
 
2019 IML workshop: A hybrid deep learning approach to vertexing
2019 IML workshop: A hybrid deep learning approach to vertexing2019 IML workshop: A hybrid deep learning approach to vertexing
2019 IML workshop: A hybrid deep learning approach to vertexing
Henry Schreiner
 
LHCb Computing Workshop 2018: PV finding with CNNs
LHCb Computing Workshop 2018: PV finding with CNNsLHCb Computing Workshop 2018: PV finding with CNNs
LHCb Computing Workshop 2018: PV finding with CNNs
Henry Schreiner
 

More from Henry Schreiner (16)

Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024
 
Software Quality Assurance Tooling - Wintersession 2024
Software Quality Assurance Tooling - Wintersession 2024Software Quality Assurance Tooling - Wintersession 2024
Software Quality Assurance Tooling - Wintersession 2024
 
Princeton RSE Peer network first meeting
Princeton RSE Peer network first meetingPrinceton RSE Peer network first meeting
Princeton RSE Peer network first meeting
 
Software Quality Assurance Tooling 2023
Software Quality Assurance Tooling 2023Software Quality Assurance Tooling 2023
Software Quality Assurance Tooling 2023
 
Princeton Wintersession: Software Quality Assurance Tooling
Princeton Wintersession: Software Quality Assurance ToolingPrinceton Wintersession: Software Quality Assurance Tooling
Princeton Wintersession: Software Quality Assurance Tooling
 
Everything you didn't know you needed
Everything you didn't know you neededEverything you didn't know you needed
Everything you didn't know you needed
 
SciPy22 - Building binary extensions with pybind11, scikit build, and cibuild...
SciPy22 - Building binary extensions with pybind11, scikit build, and cibuild...SciPy22 - Building binary extensions with pybind11, scikit build, and cibuild...
SciPy22 - Building binary extensions with pybind11, scikit build, and cibuild...
 
SciPy 2022 Scikit-HEP
SciPy 2022 Scikit-HEPSciPy 2022 Scikit-HEP
SciPy 2022 Scikit-HEP
 
PyCon 2022 -Scikit-HEP Developer Pages: Guidelines for modern packaging
PyCon 2022 -Scikit-HEP Developer Pages: Guidelines for modern packagingPyCon 2022 -Scikit-HEP Developer Pages: Guidelines for modern packaging
PyCon 2022 -Scikit-HEP Developer Pages: Guidelines for modern packaging
 
PyCon2022 - Building Python Extensions
PyCon2022 - Building Python ExtensionsPyCon2022 - Building Python Extensions
PyCon2022 - Building Python Extensions
 
boost-histogram / Hist: PyHEP Topical meeting
boost-histogram / Hist: PyHEP Topical meetingboost-histogram / Hist: PyHEP Topical meeting
boost-histogram / Hist: PyHEP Topical meeting
 
HOW 2019: Machine Learning for the Primary Vertex Reconstruction
HOW 2019: Machine Learning for the Primary Vertex ReconstructionHOW 2019: Machine Learning for the Primary Vertex Reconstruction
HOW 2019: Machine Learning for the Primary Vertex Reconstruction
 
ACAT 2019: A hybrid deep learning approach to vertexing
ACAT 2019: A hybrid deep learning approach to vertexingACAT 2019: A hybrid deep learning approach to vertexing
ACAT 2019: A hybrid deep learning approach to vertexing
 
2019 CtD: A hybrid deep learning approach to vertexing
2019 CtD: A hybrid deep learning approach to vertexing2019 CtD: A hybrid deep learning approach to vertexing
2019 CtD: A hybrid deep learning approach to vertexing
 
2019 IML workshop: A hybrid deep learning approach to vertexing
2019 IML workshop: A hybrid deep learning approach to vertexing2019 IML workshop: A hybrid deep learning approach to vertexing
2019 IML workshop: A hybrid deep learning approach to vertexing
 
LHCb Computing Workshop 2018: PV finding with CNNs
LHCb Computing Workshop 2018: PV finding with CNNsLHCb Computing Workshop 2018: PV finding with CNNs
LHCb Computing Workshop 2018: PV finding with CNNs
 

Recently uploaded

LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 

Recently uploaded (20)

LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 

PyHEP 2019: Python 3.8

  • 2. New in Python • Python 3.6 ▶ Big update ▶ First version fast as 2.7 ▶ New f-strings very popular • Python 3.7 ▶ First version faster than 2.7 ▶ OpenSSL update has affected adoption • Python 3.8 ▶ Released just a few days ago! ▶ What’s new? 1/13Henry Schreiner Python 3.8 October 18, 2019
  • 3. Themes • Performance • ABI / Internals • Static typing 2/13Henry Schreiner Python 3.8 October 18, 2019
  • 4. Python 3.8: Positional-only arguments d = dict(one=1, two=2) d = dict({'one':1, 'two':2} Challenge: write dict yourself 3/13Henry Schreiner Python 3.8 October 18, 2019
  • 5. Python 3.8: Positional-only arguments d = dict(one=1, two=2) d = dict({'one':1, 'two':2} Challenge: write dict yourself def dict(arg=None, **kargs): ... dict(arg=3) # OOPS! You have to use *args, and limit to 1 arg yourself. Or… 3/13Henry Schreiner Python 3.8 October 18, 2019
  • 6. Python 3.8: Positional-only arguments (2) If you look at the signatures of dict, pow, or some other builtins, you will see something kind of like this: def dict(arg=None, /, **kargs): ... That is now valid Python in 3.8! Why is it useful? • Allow kwargs and positional arguments without overlap • Force positional arguments without names • You can change the internal name - not part of your API def f(pos, /, pos_or_kw, *, kw_required, kw_optional=None): ... 4/13Henry Schreiner Python 3.8 October 18, 2019
  • 7. Python 3.8: Walrus operator Assignment in Python is a statement (limited): item = ... # simple item[...] = ... # item item.attr = ... # attr a, b, = ... # tuple a = b = ... # chained (special case) But what about assigning in other places, like in the C languages? if x = True: # Will never be allowed, too easy to make mistake f(x=True) # Keyword argument 5/13Henry Schreiner Python 3.8 October 18, 2019
  • 8. Python 3.8: Walrus operator (2) Solution: A new operator! • Spelling: := (looks like a sideways walrus) • Works almost anywhere normal = doesn’t (one way to do things) • Often requires parenthesis for clarity if res := check(): print(res) a = [None, 0, 1, 2] while a := b.pop(): print(a) • Use carefully: could make code harder to read • C++17/C++20 adding variable defines in loops for similar reasons • Scope leaks, (un?)fortunately 6/13Henry Schreiner Python 3.8 October 18, 2019
  • 9. Python 3.8: f-string debugging In Python 3.6, f-strings make string interpolation easy: >>> x = 3 >>> print(f"x = {x}") x = 3 Debugging is now DRY with the = specifier: >>> print(f"{x = }") x = 3 • Spaces respected • Mix with complex expressions or formatting 7/13Henry Schreiner Python 3.8 October 18, 2019
  • 10. Python 3.8: Static typing Static type hints are a big feature of Python 3, and now they are much more powerful: Literals type (AKA make-shift enums) def f(val : Literal['yes', 'no', 'auto']): ... Final (AKA const) x : Final[bool] = True x = False # Invalid in type checker like mypy Protocols (ACA C++20 Concepts / Java Interface) class HasName(Protocol): name: str Now you can use HasName, will require a name attribute. 8/13Henry Schreiner Python 3.8 October 18, 2019
  • 11. TypedASDT • TypedAST merged into Python! • feature_version selector (3.4+) >>> import ast >>> s = ast.parse('x = 2 # type: Int', type_comments=True) >>> ast.dump(s) "Module(body=[Assign( targets=[Name(id='x', ctx=Store())], value=Constant(value=2, kind=None), type_comment='Int')], type_ignores=[])" • ast.get_source_segment gets the source for a bit of ast, if location information is present. 9/13Henry Schreiner Python 3.8 October 18, 2019
  • 12. Other features • TypedDict gives types to dict parts • importlib.metadata gives you info from installed packages (like importlib.resources) • math and statistics have new functions • namedtuple, pickle, and more are faster • SyntaxError messages are more detailed in some common cases • multiprocessing.shared_memory – can avoid pickle transfer of objects • reversed works on dicts • Unpacking in return/yield 10/13Henry Schreiner Python 3.8 October 18, 2019
  • 13. Other developer changes • --libs no longer include libpython • Single ABI for debug/release • Runtime audit hooks • New C API for initialization • Provisional vectorcall protocol – fast calling of C functions • Pickle support out-of-band data (multiple streams) (Protocol 5) • __code__ now has .replace, like __signature__ 11/13Henry Schreiner Python 3.8 October 18, 2019
  • 14. Final Words Released • Python.org released • Docker: docker run --rm -it python:3.8 • Scikit-HEP GCC 9.2 ManyLinux1 containers Not yet released • Conda: Coming soon • Numpy wheels • Homebrew: In progress • Still missing in Azure, etc. • Scikit-HEP build tools (Windows, ManyLinux1 + GCC 9.2) 12/13Henry Schreiner Python 3.8 October 18, 2019
  • 15. Sources • Official docs • RealPython article • DeepSource This presentation available at /henryiii/python38. 13/13Henry Schreiner Python 3.8 October 18, 2019