FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pythonnative/tests/typing/conformance_components.py at main · pythonnative/pythonnative · GitHub
pythonnative
pythonnative
Repository navigation
Code
Issues
11
(11)
Pull requests
4
(4)
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
pythonnative
/
tests
/
typing
/
conformance_components.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
63 lines (45 loc) · 1.91 KB
Breadcrumbs
pythonnative
/
tests
/
typing
/
conformance_components.py
Copy path
File metadata and controls
63 lines (45 loc) · 1.91 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""Typing conformance: components, children, and keys.
Checked by mypy (see tests/test_typing_conformance.py); never imported
or executed. Each line that must be rejected carries a
``# type: ignore[code]``, so with ``warn_unused_ignores`` an API that
stops rejecting the mistake fails the check.
"""
from
__future__
import
annotations
from
typing
import
Callable
import
pythonnative
as
pn
@
pn
.
component
def
Card
(
title
:
str
,
count
:
int
=
0
)
->
pn
.
Node
:
return
pn
.
Text
(
f"
{
title
}
:
{
count
}
"
)
@
pn
.
component
def
Panel
(
*
children
:
pn
.
Node
,
title
:
str
=
""
)
->
pn
.
Node
:
return
pn
.
Column
(
pn
.
Text
(
title
),
*
children
)
@
pn
.
component
def
Toggle
(
on_change
:
Callable
[[
bool
],
None
],
value
:
bool
=
False
)
->
pn
.
Node
:
return
pn
.
Switch
(
value
=
value
,
on_change
=
on_change
)
def
accepted
(
flag
:
bool
,
labels
:
list
[
str
])
->
pn
.
Node
:
card
:
pn
.
Element
=
Card
(
title
=
"Hello"
)
positional
=
Card
(
"Hello"
,
2
)
keyed
:
pn
.
Element
=
Card
(
title
=
"x"
).
with_key
(
3
)
column
=
pn
.
Column
(
pn
.
Text
(
"x"
)
if
flag
else
None
,
flag
and
pn
.
Text
(
"y"
),
[
pn
.
Text
(
label
).
with_key
(
label
)
for
label
in
labels
],
(
Card
(
title
=
label
).
with_key
(
label
)
for
label
in
labels
),
pn
.
Text
(
"keyed"
,
key
=
"k"
),
)
panel
=
Panel
(
card
,
positional
,
keyed
,
column
,
title
=
"Panel"
)
toggle
=
Toggle
(
on_change
=
lambda
value
:
None
)
return
[
panel
,
toggle
,
None
,
False
]
def
no_arguments
()
->
None
:
return
None
def
rejected
()
->
None
:
Card
(
title
=
1
)
# type: ignore[arg-type]
Card
(
key
=
"k"
,
title
=
"x"
)
# type: ignore[call-arg]
Card
(
titel
=
"x"
)
# type: ignore[call-arg]
Card
()
# type: ignore[call-arg]
Panel
(
pn
.
Text
(
"x"
),
title
=
None
)
# type: ignore[arg-type]
Toggle
(
on_change
=
no_arguments
)
# type: ignore[arg-type]
pn
.
Text
(
"x"
,
selectable
=
"yes"
)
# type: ignore[arg-type]
pn
.
Column
(
pn
.
Text
(
"x"
),
3
)
# type: ignore[arg-type]
def
returns_a_number
()
->
pn
.
Node
:
return
3
# type: ignore[return-value]
Back
|
FazBrowse Home
|
New Git URL