Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/pyright-internal/src/analyzer/typeEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12303,7 +12303,9 @@ export function createTypeEvaluator(
const paramName = argParam.paramName;
if (passedName !== paramName) {
addDiagnostic(
DiagnosticRule.reportPositionalArgumentNameMismatch,
FunctionType.isBuiltIn(type)
? DiagnosticRule.reportPositionalArgumentNameMismatchForBuiltIns
: DiagnosticRule.reportPositionalArgumentNameMismatch,
`Positional argument "${passedName}" does not match parameter name "${paramName}"; pass as a keyword argument to avoid confusion`,
a.valueExpression
);
Expand Down
9 changes: 9 additions & 0 deletions packages/pyright-internal/src/common/configOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ export interface DiagnosticRuleSet {
// Report mismatch between positional argument names and parameter names when requested by decorator?
reportPositionalArgumentNameMismatch: DiagnosticLevel;

// Report mismatch between positional argument names and parameter names for built-in functions?
reportPositionalArgumentNameMismatchForBuiltIns: DiagnosticLevel;

// Report inconsistencies with function overload signatures?
reportInconsistentOverload: DiagnosticLevel;

Expand Down Expand Up @@ -625,6 +628,7 @@ export function getOffDiagnosticRuleSet(): DiagnosticRuleSet {
reportAttributeAccessIssue: 'none',
reportCallIssue: 'none',
reportPositionalArgumentNameMismatch: 'none',
reportPositionalArgumentNameMismatchForBuiltIns: 'none',
reportInconsistentOverload: 'none',
reportIndexIssue: 'none',
reportInvalidTypeArguments: 'none',
Expand Down Expand Up @@ -745,6 +749,7 @@ export function getBasicDiagnosticRuleSet(): DiagnosticRuleSet {
reportAttributeAccessIssue: 'error',
reportCallIssue: 'error',
reportPositionalArgumentNameMismatch: 'none',
reportPositionalArgumentNameMismatchForBuiltIns: 'none',
reportInconsistentOverload: 'error',
reportIndexIssue: 'error',
reportInvalidTypeArguments: 'error',
Expand Down Expand Up @@ -865,6 +870,7 @@ export function getStandardDiagnosticRuleSet(): DiagnosticRuleSet {
reportAttributeAccessIssue: 'error',
reportCallIssue: 'error',
reportPositionalArgumentNameMismatch: 'none',
reportPositionalArgumentNameMismatchForBuiltIns: 'none',
reportInconsistentOverload: 'error',
reportIndexIssue: 'error',
reportInvalidTypeArguments: 'error',
Expand Down Expand Up @@ -1060,6 +1066,7 @@ export const getRecommendedDiagnosticRuleSet = (): DiagnosticRuleSet => ({
reportIncompatibleUnannotatedOverride: 'none', // TODO: change to error when we're confident there's no performance issues with this rule
reportInvalidAbstractMethod: 'warning',
reportPositionalArgumentNameMismatch: 'warning',
reportPositionalArgumentNameMismatchForBuiltIns: 'none',
allowedUntypedLibraries: [],
});

Expand Down Expand Up @@ -1176,6 +1183,7 @@ export const getAllDiagnosticRuleSet = (): DiagnosticRuleSet => ({
reportIncompatibleUnannotatedOverride: 'error',
reportInvalidAbstractMethod: 'error',
reportPositionalArgumentNameMismatch: 'error',
reportPositionalArgumentNameMismatchForBuiltIns: 'none',
allowedUntypedLibraries: [],
});

Expand Down Expand Up @@ -1217,6 +1225,7 @@ export function getStrictDiagnosticRuleSet(): DiagnosticRuleSet {
reportAttributeAccessIssue: 'error',
reportCallIssue: 'error',
reportPositionalArgumentNameMismatch: 'warning',
reportPositionalArgumentNameMismatchForBuiltIns: 'none',
reportInconsistentOverload: 'error',
reportIndexIssue: 'error',
reportInvalidTypeArguments: 'error',
Expand Down
1 change: 1 addition & 0 deletions packages/pyright-internal/src/common/diagnosticRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export enum DiagnosticRule {
reportShadowedImports = 'reportShadowedImports',
reportImplicitOverride = 'reportImplicitOverride',
reportPositionalArgumentNameMismatch = 'reportPositionalArgumentNameMismatch',
reportPositionalArgumentNameMismatchForBuiltIns = 'reportPositionalArgumentNameMismatchForBuiltIns',

// basedpyright options:
failOnWarnings = 'failOnWarnings',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,20 @@ test('it reports an error', () => {
],
});
});

test('it reports an error for built-in functions', () => {
const configOptions = new ConfigOptions(Uri.empty());
configOptions.diagnosticRuleSet.reportPositionalArgumentNameMismatchForBuiltIns = 'warning';
configOptions.diagnosticRuleSet.reportUnusedParameter = 'none';

const analysisResults = TestUtils.typeAnalyzeSampleFiles(['argumentsMatchParamNames.py'], configOptions);

TestUtils.validateResultsButBased(analysisResults, {
warnings: [
{
line: 25,
code: DiagnosticRule.reportPositionalArgumentNameMismatchForBuiltIns,
},
],
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ def foo(
height, # okay, matches
width=length, # okay, using keyword
)

iterable = []
len(iterable) # okay, built-in function