mirror of
https://github.com/microsoft/pyright.git
synced 2024-10-07 05:17:10 +03:00
Added keyword-only check to dataclasess __match_args__
(#2615)
* Add keyword-only check to dataclasess `__match_args__` * Fixed tests added in add keyword-only check to dataclasess `__match_args__`
This commit is contained in:
parent
b269ee9a85
commit
736e41c63c
@ -406,7 +406,7 @@ export function synthesizeDataClassMethods(
|
||||
) {
|
||||
const matchArgsNames: string[] = [];
|
||||
fullDataClassEntries.forEach((entry) => {
|
||||
if (entry.includeInInit) {
|
||||
if (entry.includeInInit && !entry.isKeywordOnly) {
|
||||
// Use the field name, not its alias (if it has one).
|
||||
matchArgsNames.push(entry.name);
|
||||
}
|
||||
|
17
packages/pyright-internal/src/tests/samples/match8.py
Normal file
17
packages/pyright-internal/src/tests/samples/match8.py
Normal file
@ -0,0 +1,17 @@
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Literal
|
||||
|
||||
@dataclass
|
||||
class Point:
|
||||
optional: int | None = field(default=None, kw_only=True)
|
||||
x: int
|
||||
y: int
|
||||
|
||||
|
||||
obj = Point(1, 2)
|
||||
match obj:
|
||||
case Point(x, y, optional=opt):
|
||||
t_v1: Literal["int"] = reveal_type(x)
|
||||
t_v2: Literal["int"] = reveal_type(y)
|
||||
t_v3: Literal["int | None"] = reveal_type(opt)
|
||||
distance = (x ** 2 + y ** 2) ** 0.5
|
@ -659,6 +659,14 @@ test('Match7', () => {
|
||||
TestUtils.validateResults(analysisResults, 2);
|
||||
});
|
||||
|
||||
test('Match8', () => {
|
||||
const configOptions = new ConfigOptions('.');
|
||||
|
||||
configOptions.defaultPythonVersion = PythonVersion.V3_10;
|
||||
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['match8.py'], configOptions);
|
||||
TestUtils.validateResults(analysisResults, 0);
|
||||
});
|
||||
|
||||
test('List1', () => {
|
||||
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['list1.py']);
|
||||
TestUtils.validateResults(analysisResults, 0);
|
||||
|
Loading…
Reference in New Issue
Block a user