Skip to content

Commit

Permalink
add test for subscripting AbstractContextManager on 3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
DetachHead committed Apr 9, 2024
1 parent e319afa commit 186a41f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/pyright-internal/src/tests/samples/subscript_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from contextlib import AbstractContextManager
from typing import ContextManager

ContextManagerAlias = ContextManager
AbstractContextManagerAlias = AbstractContextManager

foo: ContextManagerAlias[None]
bar: AbstractContextManagerAlias[None] # error
baz: ContextManager[None]
qux: AbstractContextManager[None] # error
15 changes: 15 additions & 0 deletions packages/pyright-internal/src/tests/typeEvaluatorBased.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { BasedConfigOptions, ConfigOptions } from '../common/configOptions';
import { DiagnosticRule } from '../common/diagnosticRules';
import { pythonVersion3_8 } from '../common/pythonVersion';
import { Uri } from '../common/uri/uri';
import { UriEx } from '../common/uri/uriUtils';
import { resolveSampleFilePath, typeAnalyzeSampleFiles, validateResultsButBased } from './testUtils';
Expand Down Expand Up @@ -75,3 +76,17 @@ test('reportInvalidCast', () => {
],
});
});

test('subscript context manager types on 3.8', () => {
const configOptions = new ConfigOptions(Uri.empty());
configOptions.defaultPythonVersion = pythonVersion3_8;
const analysisResults = typeAnalyzeSampleFiles(['subscript_check.py'], configOptions);
const message =
'Subscript for class "AbstractContextManager" will generate runtime exception; enclose type annotation in quotes';
validateResultsButBased(analysisResults, {
errors: [
{ code: DiagnosticRule.reportGeneralTypeIssues, line: 7, message },
{ code: DiagnosticRule.reportGeneralTypeIssues, line: 9, message },
],
});
});

0 comments on commit 186a41f

Please sign in to comment.