<!--
Generated by the pyrx RPG docs pipeline from ../../.rpg/rpg_encoder.json.
Do not edit directly — changes will be overwritten by the next refresh.
Graph repo_sha: 784698179a5627072df39bbe0fcadb55bb7dd408
Graph generated_at: 2026-06-10T00:19:36.841Z
-->
# Flow Narrowing and Type Guards

**Feature path:** `Flow Narrowing and Type Guards`

## Implementation summary

- **Files:** 6
- **Symbols:** 67

### Primary files

These are the main implementation files attached to this semantic node.

| File | Summary |
| ---- | ------- |
| [packages/pyright/packages/pyright-internal/src/analyzer/codeFlowEngine.ts](https://github.com/microsoft/pyrx/blob/784698179a5627072df39bbe0fcadb55bb7dd408/packages/pyright/packages/pyright-internal/src/analyzer/codeFlowEngine.ts#L1-L2061) | Determines narrowed types for variables and expressions and computes statement reachability via the code flow graph |
| [packages/pyright/packages/pyright-internal/src/analyzer/codeFlowTypes.ts](https://github.com/microsoft/pyrx/blob/784698179a5627072df39bbe0fcadb55bb7dd408/packages/pyright/packages/pyright-internal/src/analyzer/codeFlowTypes.ts#L1-L286) | Types and helpers for tracking code-flow nodes and reference keys used in Pyright's code flow analysis |
| [packages/pyright/packages/pyright-internal/src/analyzer/codeFlowUtils.ts](https://github.com/microsoft/pyrx/blob/784698179a5627072df39bbe0fcadb55bb7dd408/packages/pyright/packages/pyright-internal/src/analyzer/codeFlowUtils.ts#L1-L446) | Generates an ASCII diagram of a control flow graph from FlowNode structures |
| [packages/pyright/packages/pyright-internal/src/analyzer/patternMatching.ts](https://github.com/microsoft/pyrx/blob/784698179a5627072df39bbe0fcadb55bb7dd408/packages/pyright/packages/pyright-internal/src/analyzer/patternMatching.ts#L1-L2254) | Type evaluation and narrowing utilities for Python structural pattern matching (PEP 634) in Pyright |
| [packages/pyright/packages/pyright-internal/src/analyzer/staticExpressions.ts](https://github.com/microsoft/pyrx/blob/784698179a5627072df39bbe0fcadb55bb7dd408/packages/pyright/packages/pyright-internal/src/analyzer/staticExpressions.ts#L1-L377) | Evaluates parse-node expressions to determine static boolean, version, and platform string outcomes |
| [packages/pyright/packages/pyright-internal/src/analyzer/typeGuards.ts](https://github.com/microsoft/pyrx/blob/784698179a5627072df39bbe0fcadb55bb7dd408/packages/pyright/packages/pyright-internal/src/analyzer/typeGuards.ts#L1-L2814) | Narrow types based on conditional expressions, isinstance checks, and user-defined type guards |

### Symbol preview (40 of 67)

| Symbol | Kind | Source |
| ------ | ---- | ------ |
| `isIncompleteType` | function | [packages/pyright/packages/pyright-internal/src/analyzer/codeFlowEngine.ts](https://github.com/microsoft/pyrx/blob/784698179a5627072df39bbe0fcadb55bb7dd408/packages/pyright/packages/pyright-internal/src/analyzer/codeFlowEngine.ts#L162-L164) |
| `getCodeFlowEngine` | function | [packages/pyright/packages/pyright-internal/src/analyzer/codeFlowEngine.ts](https://github.com/microsoft/pyrx/blob/784698179a5627072df39bbe0fcadb55bb7dd408/packages/pyright/packages/pyright-internal/src/analyzer/codeFlowEngine.ts#L201-L2060) |
| `getUniqueFlowNodeId` | function | [packages/pyright/packages/pyright-internal/src/analyzer/codeFlowTypes.ts](https://github.com/microsoft/pyrx/blob/784698179a5627072df39bbe0fcadb55bb7dd408/packages/pyright/packages/pyright-internal/src/analyzer/codeFlowTypes.ts#L61-L63) |
| `isCodeFlowSupportedForReference` | function | [packages/pyright/packages/pyright-internal/src/analyzer/codeFlowTypes.ts](https://github.com/microsoft/pyrx/blob/784698179a5627072df39bbe0fcadb55bb7dd408/packages/pyright/packages/pyright-internal/src/analyzer/codeFlowTypes.ts#L170-L221) |
| `createKeyForReference` | function | [packages/pyright/packages/pyright-internal/src/analyzer/codeFlowTypes.ts](https://github.com/microsoft/pyrx/blob/784698179a5627072df39bbe0fcadb55bb7dd408/packages/pyright/packages/pyright-internal/src/analyzer/codeFlowTypes.ts#L223-L256) |
| `createKeysForReferenceSubexpressions` | function | [packages/pyright/packages/pyright-internal/src/analyzer/codeFlowTypes.ts](https://github.com/microsoft/pyrx/blob/784698179a5627072df39bbe0fcadb55bb7dd408/packages/pyright/packages/pyright-internal/src/analyzer/codeFlowTypes.ts#L258-L282) |
| `formatControlFlowGraph` | function | [packages/pyright/packages/pyright-internal/src/analyzer/codeFlowUtils.ts](https://github.com/microsoft/pyrx/blob/784698179a5627072df39bbe0fcadb55bb7dd408/packages/pyright/packages/pyright-internal/src/analyzer/codeFlowUtils.ts#L28-L445) |
| `narrowTypeBasedOnPattern` | function | [packages/pyright/packages/pyright-internal/src/analyzer/patternMatching.ts](https://github.com/microsoft/pyrx/blob/784698179a5627072df39bbe0fcadb55bb7dd408/packages/pyright/packages/pyright-internal/src/analyzer/patternMatching.ts#L137-L177) |
| `checkForUnusedPattern` | function | [packages/pyright/packages/pyright-internal/src/analyzer/patternMatching.ts](https://github.com/microsoft/pyrx/blob/784698179a5627072df39bbe0fcadb55bb7dd408/packages/pyright/packages/pyright-internal/src/analyzer/patternMatching.ts#L181-L207) |
| `narrowTypeBasedOnSequencePattern` | function | [packages/pyright/packages/pyright-internal/src/analyzer/patternMatching.ts](https://github.com/microsoft/pyrx/blob/784698179a5627072df39bbe0fcadb55bb7dd408/packages/pyright/packages/pyright-internal/src/analyzer/patternMatching.ts#L209-L422) |
| `narrowTypeBasedOnAsPattern` | function | [packages/pyright/packages/pyright-internal/src/analyzer/patternMatching.ts](https://github.com/microsoft/pyrx/blob/784698179a5627072df39bbe0fcadb55bb7dd408/packages/pyright/packages/pyright-internal/src/analyzer/patternMatching.ts#L424-L450) |
| `narrowTypeBasedOnMappingPattern` | function | [packages/pyright/packages/pyright-internal/src/analyzer/patternMatching.ts](https://github.com/microsoft/pyrx/blob/784698179a5627072df39bbe0fcadb55bb7dd408/packages/pyright/packages/pyright-internal/src/analyzer/patternMatching.ts#L452-L637) |
| `getPositionalMatchArgNames` | function | [packages/pyright/packages/pyright-internal/src/analyzer/patternMatching.ts](https://github.com/microsoft/pyrx/blob/784698179a5627072df39bbe0fcadb55bb7dd408/packages/pyright/packages/pyright-internal/src/analyzer/patternMatching.ts#L641-L666) |
| `narrowTypeBasedOnLiteralPattern` | function | [packages/pyright/packages/pyright-internal/src/analyzer/patternMatching.ts](https://github.com/microsoft/pyrx/blob/784698179a5627072df39bbe0fcadb55bb7dd408/packages/pyright/packages/pyright-internal/src/analyzer/patternMatching.ts#L668-L744) |
| `narrowTypeBasedOnClassPattern` | function | [packages/pyright/packages/pyright-internal/src/analyzer/patternMatching.ts](https://github.com/microsoft/pyrx/blob/784698179a5627072df39bbe0fcadb55bb7dd408/packages/pyright/packages/pyright-internal/src/analyzer/patternMatching.ts#L746-L1067) |
| `isClassSpecialCaseForClassPattern` | function | [packages/pyright/packages/pyright-internal/src/analyzer/patternMatching.ts](https://github.com/microsoft/pyrx/blob/784698179a5627072df39bbe0fcadb55bb7dd408/packages/pyright/packages/pyright-internal/src/analyzer/patternMatching.ts#L1071-L1090) |
| `narrowTypeOfClassPatternArg` | function | [packages/pyright/packages/pyright-internal/src/analyzer/patternMatching.ts](https://github.com/microsoft/pyrx/blob/784698179a5627072df39bbe0fcadb55bb7dd408/packages/pyright/packages/pyright-internal/src/analyzer/patternMatching.ts#L1093-L1171) |
| `narrowTypeBasedOnValuePattern` | function | [packages/pyright/packages/pyright-internal/src/analyzer/patternMatching.ts](https://github.com/microsoft/pyrx/blob/784698179a5627072df39bbe0fcadb55bb7dd408/packages/pyright/packages/pyright-internal/src/analyzer/patternMatching.ts#L1173-L1270) |
| `getMappingPatternInfo` | function | [packages/pyright/packages/pyright-internal/src/analyzer/patternMatching.ts](https://github.com/microsoft/pyrx/blob/784698179a5627072df39bbe0fcadb55bb7dd408/packages/pyright/packages/pyright-internal/src/analyzer/patternMatching.ts#L1274-L1354) |
| `getSequencePatternInfo` | function | [packages/pyright/packages/pyright-internal/src/analyzer/patternMatching.ts](https://github.com/microsoft/pyrx/blob/784698179a5627072df39bbe0fcadb55bb7dd408/packages/pyright/packages/pyright-internal/src/analyzer/patternMatching.ts#L1359-L1681) |
| `getTypeOfPatternSequenceEntry` | function | [packages/pyright/packages/pyright-internal/src/analyzer/patternMatching.ts](https://github.com/microsoft/pyrx/blob/784698179a5627072df39bbe0fcadb55bb7dd408/packages/pyright/packages/pyright-internal/src/analyzer/patternMatching.ts#L1683-L1738) |
| `assignTypeToPatternTargets` | function | [packages/pyright/packages/pyright-internal/src/analyzer/patternMatching.ts](https://github.com/microsoft/pyrx/blob/784698179a5627072df39bbe0fcadb55bb7dd408/packages/pyright/packages/pyright-internal/src/analyzer/patternMatching.ts#L1742-L1981) |
| `wrapTypeInList` | function | [packages/pyright/packages/pyright-internal/src/analyzer/patternMatching.ts](https://github.com/microsoft/pyrx/blob/784698179a5627072df39bbe0fcadb55bb7dd408/packages/pyright/packages/pyright-internal/src/analyzer/patternMatching.ts#L1983-L1998) |
| `validateClassPattern` | function | [packages/pyright/packages/pyright-internal/src/analyzer/patternMatching.ts](https://github.com/microsoft/pyrx/blob/784698179a5627072df39bbe0fcadb55bb7dd408/packages/pyright/packages/pyright-internal/src/analyzer/patternMatching.ts#L2000-L2082) |
| `getPatternSubtypeNarrowingCallback` | function | [packages/pyright/packages/pyright-internal/src/analyzer/patternMatching.ts](https://github.com/microsoft/pyrx/blob/784698179a5627072df39bbe0fcadb55bb7dd408/packages/pyright/packages/pyright-internal/src/analyzer/patternMatching.ts#L2087-L2235) |
| `reportUnnecessaryPattern` | function | [packages/pyright/packages/pyright-internal/src/analyzer/patternMatching.ts](https://github.com/microsoft/pyrx/blob/784698179a5627072df39bbe0fcadb55bb7dd408/packages/pyright/packages/pyright-internal/src/analyzer/patternMatching.ts#L2237-L2253) |
| `evaluateStaticBoolExpression` | function | [packages/pyright/packages/pyright-internal/src/analyzer/staticExpressions.ts](https://github.com/microsoft/pyrx/blob/784698179a5627072df39bbe0fcadb55bb7dd408/packages/pyright/packages/pyright-internal/src/analyzer/staticExpressions.ts#L18-L174) |
| `evaluateStaticBoolLikeExpression` | function | [packages/pyright/packages/pyright-internal/src/analyzer/staticExpressions.ts](https://github.com/microsoft/pyrx/blob/784698179a5627072df39bbe0fcadb55bb7dd408/packages/pyright/packages/pyright-internal/src/analyzer/staticExpressions.ts#L179-L193) |
| `_convertTupleToVersion` | function | [packages/pyright/packages/pyright-internal/src/analyzer/staticExpressions.ts](https://github.com/microsoft/pyrx/blob/784698179a5627072df39bbe0fcadb55bb7dd408/packages/pyright/packages/pyright-internal/src/analyzer/staticExpressions.ts#L195-L251) |
| `_evaluateVersionBinaryOperation` | function | [packages/pyright/packages/pyright-internal/src/analyzer/staticExpressions.ts](https://github.com/microsoft/pyrx/blob/784698179a5627072df39bbe0fcadb55bb7dd408/packages/pyright/packages/pyright-internal/src/analyzer/staticExpressions.ts#L253-L285) |
| `_evaluateStringBinaryOperation` | function | [packages/pyright/packages/pyright-internal/src/analyzer/staticExpressions.ts](https://github.com/microsoft/pyrx/blob/784698179a5627072df39bbe0fcadb55bb7dd408/packages/pyright/packages/pyright-internal/src/analyzer/staticExpressions.ts#L287-L301) |
| `_isSysVersionInfoExpression` | function | [packages/pyright/packages/pyright-internal/src/analyzer/staticExpressions.ts](https://github.com/microsoft/pyrx/blob/784698179a5627072df39bbe0fcadb55bb7dd408/packages/pyright/packages/pyright-internal/src/analyzer/staticExpressions.ts#L303-L313) |
| `_isSysPlatformInfoExpression` | function | [packages/pyright/packages/pyright-internal/src/analyzer/staticExpressions.ts](https://github.com/microsoft/pyrx/blob/784698179a5627072df39bbe0fcadb55bb7dd408/packages/pyright/packages/pyright-internal/src/analyzer/staticExpressions.ts#L315-L325) |
| `_isOsNameInfoExpression` | function | [packages/pyright/packages/pyright-internal/src/analyzer/staticExpressions.ts](https://github.com/microsoft/pyrx/blob/784698179a5627072df39bbe0fcadb55bb7dd408/packages/pyright/packages/pyright-internal/src/analyzer/staticExpressions.ts#L327-L339) |
| `_getExpectedPlatformNameFromPlatform` | function | [packages/pyright/packages/pyright-internal/src/analyzer/staticExpressions.ts](https://github.com/microsoft/pyrx/blob/784698179a5627072df39bbe0fcadb55bb7dd408/packages/pyright/packages/pyright-internal/src/analyzer/staticExpressions.ts#L341-L360) |
| `_getExpectedOsNameFromPlatform` | function | [packages/pyright/packages/pyright-internal/src/analyzer/staticExpressions.ts](https://github.com/microsoft/pyrx/blob/784698179a5627072df39bbe0fcadb55bb7dd408/packages/pyright/packages/pyright-internal/src/analyzer/staticExpressions.ts#L362-L376) |
| `getTypeNarrowingCallback` | function | [packages/pyright/packages/pyright-internal/src/analyzer/typeGuards.ts](https://github.com/microsoft/pyrx/blob/784698179a5627072df39bbe0fcadb55bb7dd408/packages/pyright/packages/pyright-internal/src/analyzer/typeGuards.ts#L117-L861) |
| `getTypeNarrowingCallbackForAliasedCondition` | function | [packages/pyright/packages/pyright-internal/src/analyzer/typeGuards.ts](https://github.com/microsoft/pyrx/blob/784698179a5627072df39bbe0fcadb55bb7dd408/packages/pyright/packages/pyright-internal/src/analyzer/typeGuards.ts#L863-L927) |
| `getDeclsForLocalVar` | function | [packages/pyright/packages/pyright-internal/src/analyzer/typeGuards.ts](https://github.com/microsoft/pyrx/blob/784698179a5627072df39bbe0fcadb55bb7dd408/packages/pyright/packages/pyright-internal/src/analyzer/typeGuards.ts#L932-L980) |
| `getTypeNarrowingCallbackForAssignmentExpression` | function | [packages/pyright/packages/pyright-internal/src/analyzer/typeGuards.ts](https://github.com/microsoft/pyrx/blob/784698179a5627072df39bbe0fcadb55bb7dd408/packages/pyright/packages/pyright-internal/src/analyzer/typeGuards.ts#L982-L993) |
| _27 additional symbols omitted_ |  |  |

## Dependencies

**Imported by:**

- `packages/pyright/packages/pyright-internal/src/analyzer/analyzerNodeInfo.ts`
- `packages/pyright/packages/pyright-internal/src/analyzer/binder.ts`
- `packages/pyright/packages/pyright-internal/src/analyzer/checker.ts`
- `packages/pyright/packages/pyright-internal/src/analyzer/dataClasses.ts`
- `packages/pyright/packages/pyright-internal/src/analyzer/enums.ts`
- `packages/pyright/packages/pyright-internal/src/analyzer/namedTuples.ts`
- `packages/pyright/packages/pyright-internal/src/analyzer/operations.ts`
- `packages/pyright/packages/pyright-internal/src/analyzer/typeEvaluator.ts`
- `packages/pyright/packages/pyright-internal/src/analyzer/typeEvaluatorTypes.ts`

**Imports:**

- `packages/pyright/packages/pyright-internal/src/analyzer/analyzerNodeInfo.ts`
- `packages/pyright/packages/pyright-internal/src/analyzer/constraintSolver.ts`
- `packages/pyright/packages/pyright-internal/src/analyzer/constraintTracker.ts`
- `packages/pyright/packages/pyright-internal/src/analyzer/constructors.ts`
- `packages/pyright/packages/pyright-internal/src/analyzer/declaration.ts`
- `packages/pyright/packages/pyright-internal/src/analyzer/enums.ts`
- `packages/pyright/packages/pyright-internal/src/analyzer/parseTreeUtils.ts`
- `packages/pyright/packages/pyright-internal/src/analyzer/scope.ts`
- `packages/pyright/packages/pyright-internal/src/analyzer/scopeUtils.ts`
- `packages/pyright/packages/pyright-internal/src/analyzer/symbol.ts`
- `packages/pyright/packages/pyright-internal/src/analyzer/typeCacheUtils.ts`
- `packages/pyright/packages/pyright-internal/src/analyzer/typeEvaluatorTypes.ts`
- `packages/pyright/packages/pyright-internal/src/analyzer/typeUtils.ts`
- `packages/pyright/packages/pyright-internal/src/analyzer/typedDicts.ts`
- `packages/pyright/packages/pyright-internal/src/analyzer/types.ts`
- `packages/pyright/packages/pyright-internal/src/common/collectionUtils.ts`
- `packages/pyright/packages/pyright-internal/src/common/configOptions.ts`
- `packages/pyright/packages/pyright-internal/src/common/console.ts`
- `packages/pyright/packages/pyright-internal/src/common/debug.ts`
- `packages/pyright/packages/pyright-internal/src/common/diagnostic.ts`
- `packages/pyright/packages/pyright-internal/src/common/diagnosticRules.ts`
- `packages/pyright/packages/pyright-internal/src/common/positionUtils.ts`
- `packages/pyright/packages/pyright-internal/src/common/pythonVersion.ts`
- `packages/pyright/packages/pyright-internal/src/localization/localize.ts`
- `packages/pyright/packages/pyright-internal/src/parser/parseNodes.ts`
- `packages/pyright/packages/pyright-internal/src/parser/tokenizerTypes.ts`
