Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cython
Commits
0b3ccd7f
Commit
0b3ccd7f
authored
Mar 15, 2022
by
da-woods
Committed by
GitHub
Mar 15, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow None to be passed into arguments annotated as type "object" (GH-4669)
parent
23eb27c6
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
0 deletions
+27
-0
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+3
-0
tests/run/ext_type_none_arg.pyx
tests/run/ext_type_none_arg.pyx
+24
-0
No files found.
Cython/Compiler/Nodes.py
View file @
0b3ccd7f
...
@@ -973,6 +973,9 @@ class CArgDeclNode(Node):
...
@@ -973,6 +973,9 @@ class CArgDeclNode(Node):
error
(
annotation
.
pos
,
"Only Python type arguments can use typing.Optional[...]"
)
error
(
annotation
.
pos
,
"Only Python type arguments can use typing.Optional[...]"
)
else
:
else
:
self
.
or_none
=
True
self
.
or_none
=
True
elif
arg_type
is
py_object_type
:
# exclude ": object" from the None check - None is a generic object.
self
.
or_none
=
True
elif
arg_type
and
arg_type
.
is_pyobject
and
self
.
default
and
self
.
default
.
is_none
:
elif
arg_type
and
arg_type
.
is_pyobject
and
self
.
default
and
self
.
default
.
is_none
:
# "x: ... = None" => implicitly allow 'None', but warn about it.
# "x: ... = None" => implicitly allow 'None', but warn about it.
if
not
self
.
or_none
:
if
not
self
.
or_none
:
...
...
tests/run/ext_type_none_arg.pyx
View file @
0b3ccd7f
...
@@ -205,6 +205,30 @@ def object_default(object o): # always behaves like 'or None'
...
@@ -205,6 +205,30 @@ def object_default(object o): # always behaves like 'or None'
"""
"""
return
type
(
o
).
__name__
return
type
(
o
).
__name__
@
cython
.
allow_none_for_extension_args
(
False
)
def
object_default_annotation
(
o
:
object
):
"""
>>> object_default_annotation(object())
'object'
>>> object_default_annotation([])
'list'
>>> object_default_annotation(None)
'NoneType'
"""
return
type
(
o
).
__name__
# no decorator
def
object_default_annotation2
(
o
:
object
):
"""
>>> object_default_annotation2(object())
'object'
>>> object_default_annotation2([])
'list'
>>> object_default_annotation2(None)
'NoneType'
"""
return
type
(
o
).
__name__
@
cython
.
allow_none_for_extension_args
(
False
)
@
cython
.
allow_none_for_extension_args
(
False
)
def
object_default_none
(
object
o
=
None
):
# behaves like 'or None'
def
object_default_none
(
object
o
=
None
):
# behaves like 'or None'
"""
"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment