diff --git a/packages/pyright-internal/src/analyzer/typeEvaluator.ts b/packages/pyright-internal/src/analyzer/typeEvaluator.ts index 739adcdec8..5131f637f4 100644 --- a/packages/pyright-internal/src/analyzer/typeEvaluator.ts +++ b/packages/pyright-internal/src/analyzer/typeEvaluator.ts @@ -5305,7 +5305,7 @@ export function createTypeEvaluator( } // See if we need to log an "unknown member access" diagnostic. - let skipPartialUnknownCheck = typeResult.isIncomplete; + let skipPartialUnknownCheck = typeResult.isIncomplete || flags & EvalFlags.AllowAnyOrUnknown; // Don't report an error if the type is a partially-specialized // class being passed as an argument. This comes up frequently in @@ -10269,7 +10269,8 @@ export function createTypeEvaluator( let castFromType = getTypeOfArgument( argList[1], /* inferenceContext */ undefined, - /* signatureTracker */ undefined + /* signatureTracker */ undefined, + EvalFlags.AllowAnyOrUnknown ).type; if (castFromType.props?.specialForm) { @@ -20767,7 +20768,8 @@ export function createTypeEvaluator( function getTypeOfArgument( arg: FunctionArgument, inferenceContext: InferenceContext | undefined, - signatureTracker: UniqueSignatureTracker | undefined + signatureTracker: UniqueSignatureTracker | undefined, + flags: EvalFlags = EvalFlags.None ): TypeResult { if (arg.typeResult) { const type = arg.typeResult.type; @@ -20781,12 +20783,7 @@ export function createTypeEvaluator( // If there was no defined type provided, there should always // be a value expression from which we can retrieve the type. - const typeResult = getTypeOfExpression( - arg.valueExpression, - /* flags */ undefined, - inferenceContext, - signatureTracker - ); + const typeResult = getTypeOfExpression(arg.valueExpression, flags, inferenceContext, signatureTracker); if (signatureTracker) { typeResult.type = ensureFunctionSignaturesAreUnique( diff --git a/packages/pyright-internal/src/analyzer/typeEvaluatorTypes.ts b/packages/pyright-internal/src/analyzer/typeEvaluatorTypes.ts index e983bf280d..f6b3f07c24 100644 --- a/packages/pyright-internal/src/analyzer/typeEvaluatorTypes.ts +++ b/packages/pyright-internal/src/analyzer/typeEvaluatorTypes.ts @@ -162,6 +162,9 @@ export const enum EvalFlags { // with the second argument to isinstance and issubclass calls. IsinstanceArg = 1 << 29, + /** don't report an error if the type is `Any` or "Unknown" */ + AllowAnyOrUnknown = 1 << 30, + // Defaults used for evaluating the LHS of a call expression. CallBaseDefaults = NoSpecialize, diff --git a/packages/pyright-internal/src/tests/samples/reportAny.py b/packages/pyright-internal/src/tests/samples/reportAny.py index 769eb54c1c..5607631790 100644 --- a/packages/pyright-internal/src/tests/samples/reportAny.py +++ b/packages/pyright-internal/src/tests/samples/reportAny.py @@ -1,4 +1,4 @@ -from typing import Any, Callable +from typing import Any, Callable, cast def foo(bar: Any) -> Any: @@ -17,4 +17,7 @@ def baz() -> None: ... match(bar): case _: - ... \ No newline at end of file + ... + +cast(int, bar) +cast(int, bar.asdf) \ No newline at end of file