mirror of
https://github.com/microsoft/pyright.git
synced 2024-09-11 07:55:56 +03:00
Changed strictParameterNoneValue
to default to true rather than false. This reflects the updated guidance in PEP 484, which indicates that type checkers should not assume that a default argument of None
should imply an Optional
type.
This commit is contained in:
parent
a1d23cd614
commit
dc24fab779
@ -48,7 +48,7 @@ The following settings control pyright’s diagnostic output (warnings or errors
|
||||
|
||||
**strictSetInference** [boolean]: When inferring the type of a set, use strict type assumptions. For example, the expression `{1, 'a', 3.4}` could be inferred to be of type `Set[Any]` or `Set[Union[int, str, float]]`. If this setting is true, it will use the latter (stricter) type. The default value for this setting is 'false'.
|
||||
|
||||
**strictParameterNoneValue** [boolean]: PEP 484 indicates that when a function parameter is assigned a default value of None, its type should implicitly be Optional even if the explicit type is not. When enabled, this rule requires that parameter type annotations use Optional explicitly in this case. The default value for this setting is 'false'.
|
||||
**strictParameterNoneValue** [boolean]: PEP 484 indicates that when a function parameter is assigned a default value of None, its type should implicitly be Optional even if the explicit type is not. When enabled, this rule requires that parameter type annotations use Optional explicitly in this case. The default value for this setting is 'true'.
|
||||
|
||||
**enableTypeIgnoreComments** [boolean]: PEP 484 defines support for "# type: ignore" comments. This switch enables or disables support for these comments. The default value for this setting is 'true'.
|
||||
|
||||
@ -279,7 +279,7 @@ The following table lists the default severity levels for each diagnostic rule w
|
||||
| strictListInference | false | false | true |
|
||||
| strictDictionaryInference | false | false | true |
|
||||
| strictSetInference | false | false | true |
|
||||
| strictParameterNoneValue | false | false | true |
|
||||
| strictParameterNoneValue | true | true | true |
|
||||
| enableTypeIgnoreComments | true | true | true |
|
||||
| reportGeneralTypeIssues | "none" | "error" | "error" |
|
||||
| reportPropertyTypeMismatch | "none" | "none" | "none" |
|
||||
|
@ -393,7 +393,7 @@ export function getOffDiagnosticRuleSet(): DiagnosticRuleSet {
|
||||
strictListInference: false,
|
||||
strictSetInference: false,
|
||||
strictDictionaryInference: false,
|
||||
strictParameterNoneValue: false,
|
||||
strictParameterNoneValue: true,
|
||||
enableTypeIgnoreComments: true,
|
||||
reportGeneralTypeIssues: 'none',
|
||||
reportPropertyTypeMismatch: 'none',
|
||||
@ -468,7 +468,7 @@ export function getBasicDiagnosticRuleSet(): DiagnosticRuleSet {
|
||||
strictListInference: false,
|
||||
strictSetInference: false,
|
||||
strictDictionaryInference: false,
|
||||
strictParameterNoneValue: false,
|
||||
strictParameterNoneValue: true,
|
||||
enableTypeIgnoreComments: true,
|
||||
reportGeneralTypeIssues: 'error',
|
||||
reportPropertyTypeMismatch: 'none',
|
||||
|
@ -1,7 +1,7 @@
|
||||
# This sample tests the type checker's handling of ClassVar
|
||||
# as described in PEP 526.
|
||||
|
||||
from typing import Any, ClassVar, Dict
|
||||
from typing import Any, ClassVar, Dict, Optional
|
||||
|
||||
|
||||
class MyDescriptor:
|
||||
@ -18,7 +18,7 @@ class Starship:
|
||||
stats: ClassVar[Dict[str, int]] = {}
|
||||
desc: ClassVar[MyDescriptor] = MyDescriptor()
|
||||
|
||||
def __init__(self, damage: int, captain: str = None):
|
||||
def __init__(self, damage: int, captain: Optional[str] = None):
|
||||
self.damage = damage
|
||||
if captain:
|
||||
self.captain = captain # Else keep the default
|
||||
|
@ -123,7 +123,7 @@
|
||||
"$id": "#/properties/strictParameterNoneValue",
|
||||
"type": "boolean",
|
||||
"title": "Allow implicit Optional when default parameter value is None",
|
||||
"default": false
|
||||
"default": true
|
||||
},
|
||||
"enableTypeIgnoreComments": {
|
||||
"$id": "#/properties/enableTypeIgnoreComments",
|
||||
|
Loading…
Reference in New Issue
Block a user