@@ -5224,6 +5224,46 @@ void nestedUnionTypeAlias() {
52245224 );
52255225 }
52265226
5227+ @ Test
5228+ void sentinelTypeExpressions () {
5229+ FileInput root = inferTypes ("""
5230+ MISSING = sentinel("MISSING")
5231+ left = MISSING | None
5232+ right = None | MISSING
5233+ nested = int | MISSING | None
5234+ """ );
5235+
5236+ var statements = root .statements ().statements ();
5237+ var sentinelType = ((AssignmentStatement ) statements .get (0 )).assignedValue ().typeV2 ();
5238+ assertThat (sentinelType ).isInstanceOfSatisfying (ObjectType .class ,
5239+ objectType -> assertThat (objectType .unwrappedType ()).isInstanceOfSatisfying (ClassType .class ,
5240+ classType -> assertThat (classType .fullyQualifiedName ()).isEqualTo ("sentinel" )));
5241+
5242+ for (int statementIndex : List .of (1 , 2 )) {
5243+ var type = ((AssignmentStatement ) statements .get (statementIndex )).assignedValue ().typeV2 ();
5244+ assertThat (type ).isInstanceOfSatisfying (UnionType .class ,
5245+ union -> assertThat (union .candidates ().stream ().map (PythonType ::unwrappedType ).map (FullyQualifiedNameHelper ::getFullyQualifiedName ))
5246+ .containsExactlyInAnyOrder (Optional .of ("sentinel" ), Optional .of ("NoneType" )));
5247+ }
5248+
5249+ var nestedType = ((AssignmentStatement ) statements .get (3 )).assignedValue ().typeV2 ();
5250+ assertThat (nestedType ).isInstanceOfSatisfying (UnionType .class ,
5251+ union -> assertThat (union .candidates ().stream ().map (PythonType ::unwrappedType ).map (FullyQualifiedNameHelper ::getFullyQualifiedName ))
5252+ .containsExactlyInAnyOrder (Optional .of ("int" ), Optional .of ("sentinel" ), Optional .of ("NoneType" )));
5253+ }
5254+
5255+ @ Test
5256+ void userDefinedSentinelIsNotATypeExpression () {
5257+ FileInput root = inferTypes ("""
5258+ class sentinel:
5259+ pass
5260+ result = sentinel() | None
5261+ """ );
5262+
5263+ var assignment = (AssignmentStatement ) root .statements ().statements ().get (1 );
5264+ assertThat (assignment .assignedValue ().typeV2 ()).isEqualTo (PythonType .UNKNOWN );
5265+ }
5266+
52275267 @ Test
52285268 void bitwiseOrOnValuesDoesNotCreateUnionType () {
52295269 FileInput root = inferTypes ("""
0 commit comments