mirror of
https://github.com/davidhalter/typeshed.git
synced 2026-01-30 14:45:23 +08:00
Add Optional[] for all remaining cases of x: <type> = None (#1424)
* Final round of adding Optional[] to type of arguments with default = None * Update Travis to use --no-implicit-optionals and clarify CONTRIBUTING.md
This commit is contained in:
committed by
Matthias Kramm
parent
81f77b17ec
commit
350563223f
@@ -135,7 +135,8 @@ rule is that they should be as concise as possible. Specifically:
|
||||
names, or methods and fields within a single class;
|
||||
* use a single blank line between top-level class definitions, or none
|
||||
if the classes are very small;
|
||||
* do not use docstrings.
|
||||
* do not use docstrings;
|
||||
* for arguments with a type and a default, use spaces around the `=`.
|
||||
|
||||
Imports in stubs are considered private (not part of the exported API)
|
||||
unless:
|
||||
@@ -144,6 +145,14 @@ unless:
|
||||
* they use the form ``from library import *`` which means all names
|
||||
from that library are exported.
|
||||
|
||||
For arguments with type and a default value of `None`, PEP 484
|
||||
prescribes that the type automatically becomes `Optional`. However we
|
||||
prefer explicit over implicit in this case, and require the explicit
|
||||
`Optional[]` around the type. The mypy tests enforce this (through
|
||||
the use of --no-implicit-optional) and the error looks like
|
||||
`Incompatible types in assignment (expression has type None, variable
|
||||
has type "Blah") `.
|
||||
|
||||
Stub files support forward references natively. In other words, the
|
||||
order of class declarations and type aliases does not matter in
|
||||
a stub file. You can also use the name of the class within its own
|
||||
|
||||
Reference in New Issue
Block a user