FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
learn-python/src/functions/test_function_annotations.py at master · sobitd/learn-python · GitHub
sobitd
/
learn-python
Public
forked from
trekhleb/learn-python
Notifications
You must be signed in to change notification settings
Fork
1
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
learn-python
/
src
/
functions
/
test_function_annotations.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
27 lines (18 loc) · 1 KB
Breadcrumbs
learn-python
/
src
/
functions
/
test_function_annotations.py
Copy path
File metadata and controls
27 lines (18 loc) · 1 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
"""Function Annotations.
@see: https://docs.python.org/3/tutorial/controlflow.html#function-annotations
Function annotations are completely optional metadata information about the types used
by user-defined functions.
Annotations are stored in the __annotations__ attribute of the function as a dictionary and have no
effect on any other part of the function. Parameter annotations are defined by a colon after the
parameter name, followed by an expression evaluating to the value of the annotation. Return
annotations are defined by a literal ->, followed by an expression, between the parameter list and
the colon denoting the end of the def statement.
"""
def
breakfast
(
ham
:
str
,
eggs
:
str
=
'eggs'
)
->
str
:
"""Breakfast creator.
This function has a positional argument, a keyword argument, and the return value annotated.
"""
return
ham
+
' and '
+
eggs
def
test_function_annotations
():
"""Function Annotations."""
assert
breakfast
.
__annotations__
==
{
'eggs'
:
str
,
'ham'
:
str
,
'return'
:
str
}
Back
|
FazBrowse Home
|
New Git URL