SlideShare a Scribd company logo
1 of 27
Download to read offline
The typing module in Python 3.5
Ryan Blunden

@ryan_blunden
A N O T H E R C O M P E L L I N G R E A S O N T O S T A R T U S I N G P Y T H O N 3 !
Recently returned to Australia after
three years at LinkedIn in 

Silicon Valley.
Now running RabbitBird as a freelance
developer, agile coach and technical
trainer.
Who am I?
What do you know about Python and its approach to typing?
Is there anything specific you want to learn from this session?
I F  YO U ’R E NOT AN ADVANC E D PYTHON D EVELOPER, DON’T WORRY.
About
you!
• Background and goals of the typing module
• Syntax
• Live coding demonstration
• Tips for getting started with the typing module in your own projects
• Review questions
• Q&A.
Agenda
By the end of this session, you will be able to:
• Explain why the typing module is useful
• Describe its basic capabilities
• Apply type hinting to a simple function and run a type checker against it
• Start thinking about how to use it in your own projects.
Session
objectives
Any Questions?
?
?
Types!
A C R A S H C O U R S E I N B A S I C T Y P I N G T E R M I N O L O G Y F O R P Y T H O N
a = 5  # a starts as a number.
a = ‘hello’  # Now a is a string. Python is cool with that.
Variable are not bound to specific type.
Dynamic typing
‘9’ + 5  # TypeError: Can't convert 'int' object to str implicitly
No help from the (C)Python interpreter if you do something
illegal with variable types.
// java
int a = 5;
a = “str”;  // This would cause a compilation error
Types are defined and code will not compile unless type
information matches what’s defined in code.
Static typing
Not concerned about the actual underlying type, just has to satisfy the
requirements of the calling code.
"When I see a bird that walks like a duck and swims like a
duck and quacks like a duck, I call that bird a duck.”
- JAMES WHITCOMB RILEY
# Knows nothing about the person, object but simply expects
# that it will have a method `doGreeting` to call.
def greetPerson(person):
  print(person.doGreeting())  
Duck typing
Better Documentation

Improve code by including typing information that can be validated
with an external type checker.
Find bugs

Enable static analysis tools to find bugs before code is run.
Standardisation

Standardise the typing syntax for the good of the Python ecosystem.
So after all these years,why add
a typing system to Python?
What started as a presentation in from Guido van Rossum in 2000
eventually evolved into two PEP proposals:
PEP 3107 - Syntax
PEP 484 - Type hints
The recent mypy library provided much of the inspiration and push to finally
get a type hinting solution into the Python standard library.
The typing module -
15 years in the making!
IT’ S GOAL IS TO IMPROVE C OD E QUALITY.
• Allows type information (function annotations) to be defined for function
parameters and function return values.
• Standardises the syntax for these type annotations.
• Allows for adding type information outside of the actual code itself in “stub” files.
class Person():
    def greeting() -> str:
        return ‘Hello there!'
#…

def greetPerson(person: Person) -> None:
    print(person.doGreeting());
Whatdoesthetypingmoduledo?
THE TY PIN G MODUL E HEL PS DEFINE TYP ES BUT D OESN’ T CHECK THEM.
Common
Questions About
The Typing Module
Q
A
Q
A
Python 2 compatible?
Not in code. Yes with stubs.
Q
A
Which versions of Python 3
are supported?
Python 3.5 has the typing module but mypy-lang supports
Python 3.2 onwards.
Syntax of type annotations introduced in Python 3.0.
Q
A
Will it slow down,break,crash
or do any harm to my code?
No. Not. Ever! It does not affect how code runs.
Q
A
Is Python dictating that I
have to use this now?
No, and it never will.
This is not a plot to turn Python into Java.
Q
A
Who uses static analysis
tools for Python?
• Python std lib.
• Code review and quality tools (Quantified Code, Codacy).
• IDE’s.
• Google, Dropbox, probably others.
Let’s Code!
https://github.com/ryan-blunden/python-typing
Python type hinting calls for
embracing “gradual typing"
Apply the type hinting to what you can, when you can. It
doesn’t affect how your code runs.
Tips for getting started
• Focus more on adding type hints as documentation. The mypy-lang checker still
has a long way to go.
• If you haven’t already, trial PyCharm and use the type annotations on some of
your code to see how it can aid your workflow.
• If you’re working with Python 2 code, try working with stubs.
• If you’re working with Python 3.2-3.4, use mypy.
• Choose one of your favourite open source Python libraries and create a pull
request that includes type definitions.
• If you use mypy either for type hinting or checking, install it from source 
Conclusion
• Helps find bugs
• Gradual typing approach
• Not required. Use it if you want to.
• Improves code documentation (as it is runnable and verifiable)
• Helps our IDE’s to help us
• Can be used in Python 2 and Python 3
Review Questions
• What are some of the benefits that could come from using type hints in Python?
• What versions of Python can you use the type hints in?
• What risk do the type hints pose if you apply them to existing code?
• List one way you could get started in applying type hints to one of your projects
today?
?
Wrapping up -
Our objectives were...
• Explain why the typing module is useful
• Describe its basic capabilities
• Apply type hinting to a simple function and run a type checker against it
• Start thinking about how to use it in your own projects.
Recommended Reading
Type Hints - Guido van Rossum
- PyCon 2015
Python Typeshed
Dynamic typing
Static typing
Duck Typing
PEP 3107
PEP 0484
Gradual typing
Python 3.5 typing module documentation
Python 3.5 type hinting in PyCharm 5
Mypy-lang
Python's New Type Hints in Action… In JavaScript
Why you need to install mypy-lang from source at the
moment
Thanks!

More Related Content

What's hot

Pigaios: A Tool for Diffing Source Codes against Binaries (Hacktivity 2018)
Pigaios: A Tool for Diffing Source Codes against Binaries (Hacktivity 2018)Pigaios: A Tool for Diffing Source Codes against Binaries (Hacktivity 2018)
Pigaios: A Tool for Diffing Source Codes against Binaries (Hacktivity 2018)Joxean Koret
 
C# 4.0 and .NET 4.0
C# 4.0 and .NET 4.0C# 4.0 and .NET 4.0
C# 4.0 and .NET 4.0Buu Nguyen
 
Testing Challenges within Agile Teams
Testing Challenges within Agile TeamsTesting Challenges within Agile Teams
Testing Challenges within Agile TeamsTechWell
 
Clean code and Coding Standards
Clean code and Coding StandardsClean code and Coding Standards
Clean code and Coding StandardsMahesh Salaria
 
Java Code Quality Tools
Java Code Quality ToolsJava Code Quality Tools
Java Code Quality ToolsOrest Ivasiv
 
Good coding-style, a talk made in 2008 to encourage changes in MySQL coding s...
Good coding-style, a talk made in 2008 to encourage changes in MySQL coding s...Good coding-style, a talk made in 2008 to encourage changes in MySQL coding s...
Good coding-style, a talk made in 2008 to encourage changes in MySQL coding s...Kostja Osipov
 
Working With Legacy Code
Working With Legacy CodeWorking With Legacy Code
Working With Legacy CodeAndrea Polci
 
Coding standard and coding guideline
Coding standard and coding guidelineCoding standard and coding guideline
Coding standard and coding guidelineDhananjaysinh Jhala
 
Lessons learned on software testing automation
Lessons learned on software testing automationLessons learned on software testing automation
Lessons learned on software testing automationgaoliang641
 
Programming style guildelines
Programming style guildelinesProgramming style guildelines
Programming style guildelinesRich Nguyen
 
Coding standards for java
Coding standards for javaCoding standards for java
Coding standards for javamaheshm1206
 
Testing for people who hate testing
Testing for people who hate testingTesting for people who hate testing
Testing for people who hate testingSam Bolgert
 
I'm a TDD cheat and I'm not afraid to admit it
I'm a TDD cheat and I'm not afraid to admit itI'm a TDD cheat and I'm not afraid to admit it
I'm a TDD cheat and I'm not afraid to admit itDaniel Irvine
 

What's hot (20)

Coding standard
Coding standardCoding standard
Coding standard
 
Java Code Quality Tools
Java Code Quality ToolsJava Code Quality Tools
Java Code Quality Tools
 
Pigaios: A Tool for Diffing Source Codes against Binaries (Hacktivity 2018)
Pigaios: A Tool for Diffing Source Codes against Binaries (Hacktivity 2018)Pigaios: A Tool for Diffing Source Codes against Binaries (Hacktivity 2018)
Pigaios: A Tool for Diffing Source Codes against Binaries (Hacktivity 2018)
 
C# 4.0 and .NET 4.0
C# 4.0 and .NET 4.0C# 4.0 and .NET 4.0
C# 4.0 and .NET 4.0
 
Testing Challenges within Agile Teams
Testing Challenges within Agile TeamsTesting Challenges within Agile Teams
Testing Challenges within Agile Teams
 
Clean code and Coding Standards
Clean code and Coding StandardsClean code and Coding Standards
Clean code and Coding Standards
 
Design Pattern Automation
Design Pattern AutomationDesign Pattern Automation
Design Pattern Automation
 
Java Code Quality Tools
Java Code Quality ToolsJava Code Quality Tools
Java Code Quality Tools
 
Good coding-style, a talk made in 2008 to encourage changes in MySQL coding s...
Good coding-style, a talk made in 2008 to encourage changes in MySQL coding s...Good coding-style, a talk made in 2008 to encourage changes in MySQL coding s...
Good coding-style, a talk made in 2008 to encourage changes in MySQL coding s...
 
Working With Legacy Code
Working With Legacy CodeWorking With Legacy Code
Working With Legacy Code
 
Coding standard and coding guideline
Coding standard and coding guidelineCoding standard and coding guideline
Coding standard and coding guideline
 
Lessons learned on software testing automation
Lessons learned on software testing automationLessons learned on software testing automation
Lessons learned on software testing automation
 
Programming style guildelines
Programming style guildelinesProgramming style guildelines
Programming style guildelines
 
Testing 101: Three Rules for Testing at Ombu Labs
Testing 101: Three Rules for Testing at Ombu Labs Testing 101: Three Rules for Testing at Ombu Labs
Testing 101: Three Rules for Testing at Ombu Labs
 
Coding standards for java
Coding standards for javaCoding standards for java
Coding standards for java
 
Coding standards
Coding standardsCoding standards
Coding standards
 
Code Review
Code ReviewCode Review
Code Review
 
Testing for people who hate testing
Testing for people who hate testingTesting for people who hate testing
Testing for people who hate testing
 
Spring IO 2015 Spock Workshop
Spring IO 2015 Spock WorkshopSpring IO 2015 Spock Workshop
Spring IO 2015 Spock Workshop
 
I'm a TDD cheat and I'm not afraid to admit it
I'm a TDD cheat and I'm not afraid to admit itI'm a TDD cheat and I'm not afraid to admit it
I'm a TDD cheat and I'm not afraid to admit it
 

Viewers also liked

An Introduction To Python - Modules & Solving Real World Problems
An Introduction To Python - Modules & Solving Real World ProblemsAn Introduction To Python - Modules & Solving Real World Problems
An Introduction To Python - Modules & Solving Real World ProblemsBlue Elephant Consulting
 
Python的module机制与最佳实践
Python的module机制与最佳实践Python的module机制与最佳实践
Python的module机制与最佳实践Leo Zhou
 
ZLM-Cython Build you first module
ZLM-Cython Build you first moduleZLM-Cython Build you first module
ZLM-Cython Build you first moduleVladimir Ulogov
 
Pivotal Data Labs - Technology and Tools in our Data Scientist's Arsenal
Pivotal Data Labs - Technology and Tools in our Data Scientist's Arsenal Pivotal Data Labs - Technology and Tools in our Data Scientist's Arsenal
Pivotal Data Labs - Technology and Tools in our Data Scientist's Arsenal Srivatsan Ramanujam
 
Functions and modules in python
Functions and modules in pythonFunctions and modules in python
Functions and modules in pythonKarin Lagesen
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesMatt Harrison
 

Viewers also liked (7)

An Introduction To Python - Modules & Solving Real World Problems
An Introduction To Python - Modules & Solving Real World ProblemsAn Introduction To Python - Modules & Solving Real World Problems
An Introduction To Python - Modules & Solving Real World Problems
 
Python的module机制与最佳实践
Python的module机制与最佳实践Python的module机制与最佳实践
Python的module机制与最佳实践
 
ZLM-Cython Build you first module
ZLM-Cython Build you first moduleZLM-Cython Build you first module
ZLM-Cython Build you first module
 
python.ppt
python.pptpython.ppt
python.ppt
 
Pivotal Data Labs - Technology and Tools in our Data Scientist's Arsenal
Pivotal Data Labs - Technology and Tools in our Data Scientist's Arsenal Pivotal Data Labs - Technology and Tools in our Data Scientist's Arsenal
Pivotal Data Labs - Technology and Tools in our Data Scientist's Arsenal
 
Functions and modules in python
Functions and modules in pythonFunctions and modules in python
Functions and modules in python
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 Minutes
 

Similar to Python typing module

Type Annotations in Python: Whats, Whys and Wows!
Type Annotations in Python: Whats, Whys and Wows!Type Annotations in Python: Whats, Whys and Wows!
Type Annotations in Python: Whats, Whys and Wows!Andreas Dewes
 
web programming UNIT VIII python by Bhavsingh Maloth
web programming UNIT VIII python by Bhavsingh Malothweb programming UNIT VIII python by Bhavsingh Maloth
web programming UNIT VIII python by Bhavsingh MalothBhavsingh Maloth
 
Python_Interview_Questions_And_Answers..
Python_Interview_Questions_And_Answers..Python_Interview_Questions_And_Answers..
Python_Interview_Questions_And_Answers..GajulaYuvaraj
 
Python_Introduction&DataType.pptx
Python_Introduction&DataType.pptxPython_Introduction&DataType.pptx
Python_Introduction&DataType.pptxHaythamBarakeh1
 
Blueprints: Introduction to Python programming
Blueprints: Introduction to Python programmingBlueprints: Introduction to Python programming
Blueprints: Introduction to Python programmingBhalaji Nagarajan
 
Tutorial on-python-programming
Tutorial on-python-programmingTutorial on-python-programming
Tutorial on-python-programmingChetan Giridhar
 
Python (3).pdf
Python (3).pdfPython (3).pdf
Python (3).pdfsamiwaris2
 
Python_Interview_Questions.pdf
Python_Interview_Questions.pdfPython_Interview_Questions.pdf
Python_Interview_Questions.pdfSamir Paul
 
ppt notes for python language variable data types
ppt notes for python language variable data typesppt notes for python language variable data types
ppt notes for python language variable data typesSukhpreetSingh519414
 
Raspberry using Python Session 1
Raspberry using Python Session 1Raspberry using Python Session 1
Raspberry using Python Session 1Mohamed Abd Ela'al
 
Programming with Python: Week 1
Programming with Python: Week 1Programming with Python: Week 1
Programming with Python: Week 1Ahmet Bulut
 
Software Craftmanship - Cours Polytech
Software Craftmanship - Cours PolytechSoftware Craftmanship - Cours Polytech
Software Craftmanship - Cours Polytechyannick grenzinger
 
Tips for Happier Python Debugging
Tips for Happier Python DebuggingTips for Happier Python Debugging
Tips for Happier Python DebuggingChun-Hao Chang
 

Similar to Python typing module (20)

Type Annotations in Python: Whats, Whys and Wows!
Type Annotations in Python: Whats, Whys and Wows!Type Annotations in Python: Whats, Whys and Wows!
Type Annotations in Python: Whats, Whys and Wows!
 
web programming UNIT VIII python by Bhavsingh Maloth
web programming UNIT VIII python by Bhavsingh Malothweb programming UNIT VIII python by Bhavsingh Maloth
web programming UNIT VIII python by Bhavsingh Maloth
 
Python_Interview_Questions_And_Answers..
Python_Interview_Questions_And_Answers..Python_Interview_Questions_And_Answers..
Python_Interview_Questions_And_Answers..
 
Python_Introduction&DataType.pptx
Python_Introduction&DataType.pptxPython_Introduction&DataType.pptx
Python_Introduction&DataType.pptx
 
Python intro
Python introPython intro
Python intro
 
Blueprints: Introduction to Python programming
Blueprints: Introduction to Python programmingBlueprints: Introduction to Python programming
Blueprints: Introduction to Python programming
 
Tutorial on-python-programming
Tutorial on-python-programmingTutorial on-python-programming
Tutorial on-python-programming
 
Python (3).pdf
Python (3).pdfPython (3).pdf
Python (3).pdf
 
Python PPT.pptx
Python PPT.pptxPython PPT.pptx
Python PPT.pptx
 
Python_Interview_Questions.pdf
Python_Interview_Questions.pdfPython_Interview_Questions.pdf
Python_Interview_Questions.pdf
 
python-ppt.ppt
python-ppt.pptpython-ppt.ppt
python-ppt.ppt
 
python-ppt.ppt
python-ppt.pptpython-ppt.ppt
python-ppt.ppt
 
ppt notes for python language variable data types
ppt notes for python language variable data typesppt notes for python language variable data types
ppt notes for python language variable data types
 
Raspberry using Python Session 1
Raspberry using Python Session 1Raspberry using Python Session 1
Raspberry using Python Session 1
 
Programming with Python: Week 1
Programming with Python: Week 1Programming with Python: Week 1
Programming with Python: Week 1
 
Software Craftmanship - Cours Polytech
Software Craftmanship - Cours PolytechSoftware Craftmanship - Cours Polytech
Software Craftmanship - Cours Polytech
 
Python Tutorial for Beginner
Python Tutorial for BeginnerPython Tutorial for Beginner
Python Tutorial for Beginner
 
Tips for Happier Python Debugging
Tips for Happier Python DebuggingTips for Happier Python Debugging
Tips for Happier Python Debugging
 
interviewbit.pdf
interviewbit.pdfinterviewbit.pdf
interviewbit.pdf
 
Python made easy
Python made easy Python made easy
Python made easy
 

Recently uploaded

Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noidabntitsolutionsrishis
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfLivetecs LLC
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 

Recently uploaded (20)

Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdf
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 

Python typing module

  • 1. The typing module in Python 3.5 Ryan Blunden
 @ryan_blunden A N O T H E R C O M P E L L I N G R E A S O N T O S T A R T U S I N G P Y T H O N 3 !
  • 2. Recently returned to Australia after three years at LinkedIn in 
 Silicon Valley. Now running RabbitBird as a freelance developer, agile coach and technical trainer. Who am I?
  • 3. What do you know about Python and its approach to typing? Is there anything specific you want to learn from this session? I F  YO U ’R E NOT AN ADVANC E D PYTHON D EVELOPER, DON’T WORRY. About you!
  • 4. • Background and goals of the typing module • Syntax • Live coding demonstration • Tips for getting started with the typing module in your own projects • Review questions • Q&A. Agenda
  • 5. By the end of this session, you will be able to: • Explain why the typing module is useful • Describe its basic capabilities • Apply type hinting to a simple function and run a type checker against it • Start thinking about how to use it in your own projects. Session objectives
  • 7. Types! A C R A S H C O U R S E I N B A S I C T Y P I N G T E R M I N O L O G Y F O R P Y T H O N
  • 8. a = 5  # a starts as a number. a = ‘hello’  # Now a is a string. Python is cool with that. Variable are not bound to specific type. Dynamic typing ‘9’ + 5  # TypeError: Can't convert 'int' object to str implicitly No help from the (C)Python interpreter if you do something illegal with variable types.
  • 9. // java int a = 5; a = “str”;  // This would cause a compilation error Types are defined and code will not compile unless type information matches what’s defined in code. Static typing
  • 10. Not concerned about the actual underlying type, just has to satisfy the requirements of the calling code. "When I see a bird that walks like a duck and swims like a duck and quacks like a duck, I call that bird a duck.” - JAMES WHITCOMB RILEY # Knows nothing about the person, object but simply expects # that it will have a method `doGreeting` to call. def greetPerson(person):   print(person.doGreeting())   Duck typing
  • 11. Better Documentation
 Improve code by including typing information that can be validated with an external type checker. Find bugs
 Enable static analysis tools to find bugs before code is run. Standardisation
 Standardise the typing syntax for the good of the Python ecosystem. So after all these years,why add a typing system to Python?
  • 12. What started as a presentation in from Guido van Rossum in 2000 eventually evolved into two PEP proposals: PEP 3107 - Syntax PEP 484 - Type hints The recent mypy library provided much of the inspiration and push to finally get a type hinting solution into the Python standard library. The typing module - 15 years in the making!
  • 13. IT’ S GOAL IS TO IMPROVE C OD E QUALITY. • Allows type information (function annotations) to be defined for function parameters and function return values. • Standardises the syntax for these type annotations. • Allows for adding type information outside of the actual code itself in “stub” files. class Person():     def greeting() -> str:         return ‘Hello there!' #…
 def greetPerson(person: Person) -> None:     print(person.doGreeting()); Whatdoesthetypingmoduledo? THE TY PIN G MODUL E HEL PS DEFINE TYP ES BUT D OESN’ T CHECK THEM.
  • 15. Q A Python 2 compatible? Not in code. Yes with stubs.
  • 16. Q A Which versions of Python 3 are supported? Python 3.5 has the typing module but mypy-lang supports Python 3.2 onwards. Syntax of type annotations introduced in Python 3.0.
  • 17. Q A Will it slow down,break,crash or do any harm to my code? No. Not. Ever! It does not affect how code runs.
  • 18. Q A Is Python dictating that I have to use this now? No, and it never will. This is not a plot to turn Python into Java.
  • 19. Q A Who uses static analysis tools for Python? • Python std lib. • Code review and quality tools (Quantified Code, Codacy). • IDE’s. • Google, Dropbox, probably others.
  • 21. Python type hinting calls for embracing “gradual typing" Apply the type hinting to what you can, when you can. It doesn’t affect how your code runs.
  • 22. Tips for getting started • Focus more on adding type hints as documentation. The mypy-lang checker still has a long way to go. • If you haven’t already, trial PyCharm and use the type annotations on some of your code to see how it can aid your workflow. • If you’re working with Python 2 code, try working with stubs. • If you’re working with Python 3.2-3.4, use mypy. • Choose one of your favourite open source Python libraries and create a pull request that includes type definitions. • If you use mypy either for type hinting or checking, install it from source 
  • 23. Conclusion • Helps find bugs • Gradual typing approach • Not required. Use it if you want to. • Improves code documentation (as it is runnable and verifiable) • Helps our IDE’s to help us • Can be used in Python 2 and Python 3
  • 24. Review Questions • What are some of the benefits that could come from using type hints in Python? • What versions of Python can you use the type hints in? • What risk do the type hints pose if you apply them to existing code? • List one way you could get started in applying type hints to one of your projects today? ?
  • 25. Wrapping up - Our objectives were... • Explain why the typing module is useful • Describe its basic capabilities • Apply type hinting to a simple function and run a type checker against it • Start thinking about how to use it in your own projects.
  • 26. Recommended Reading Type Hints - Guido van Rossum - PyCon 2015 Python Typeshed Dynamic typing Static typing Duck Typing PEP 3107 PEP 0484 Gradual typing Python 3.5 typing module documentation Python 3.5 type hinting in PyCharm 5 Mypy-lang Python's New Type Hints in Action… In JavaScript Why you need to install mypy-lang from source at the moment