Commit b1b23de4 authored by Stefan Behnel's avatar Stefan Behnel

Follow PEP-484 and warn about "func(x: list = None)" without an explicit...

Follow PEP-484 and warn about "func(x: list = None)" without an explicit "typing.Optional[]" declaration.

See https://github.com/cython/cython/issues/3883
parent a34d50d6
......@@ -974,7 +974,9 @@ class CArgDeclNode(Node):
else:
self.or_none = True
elif arg_type and arg_type.is_pyobject and self.default and self.default.is_none:
# "x: ... = None" => implicitly allow 'None'
# "x: ... = None" => implicitly allow 'None', but warn about it.
if not self.or_none:
warning(self.pos, "PEP-484 recommends 'typing.Optional[...]' for arguments that can be None.")
self.or_none = True
elif arg_type and arg_type.is_pyobject and not self.or_none:
self.not_none = True
......
......@@ -332,6 +332,9 @@ _WARNINGS = """
14:77: Dicts should no longer be used as type annotations. Use 'cython.int' etc. directly.
14:85: Python type declaration in signature annotation does not refer to a Python type
14:85: Strings should no longer be used for type declarations. Use 'cython.int' etc. directly.
36:64: PEP-484 recommends 'typing.Optional[...]' for arguments that can be None.
63:68: PEP-484 recommends 'typing.Optional[...]' for arguments that can be None.
90:68: PEP-484 recommends 'typing.Optional[...]' for arguments that can be None.
274:44: Unknown type declaration in annotation, ignoring
281:29: Ambiguous types in annotation, ignoring
298:15: Annotation ignored since class-level attributes must be Python objects. Were you trying to set up an instance attribute?
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment