@@ -58,6 +58,7 @@ use crate::literal::Literal;
5858use crate :: module:: ModuleType ;
5959use crate :: param_spec:: ParamSpec ;
6060use crate :: quantified:: Quantified ;
61+ use crate :: sentinel:: Sentinel ;
6162use crate :: simplify:: unions;
6263use crate :: special_form:: SpecialForm ;
6364use crate :: stdlib:: Stdlib ;
@@ -857,6 +858,9 @@ pub enum Type {
857858 /// be immediately looked up for untyping (see `TypeAliasData::TypeAliasRef`), `UntypedAlias`
858859 /// stores a reference that is untyped once we actually look up the value.
859860 UntypedAlias ( Box < TypeAliasData > ) ,
861+ // Sentinel types, documented here: https://docs.python.org/3.15/library/functions.html#sentinel
862+ // First introduced in PEP 661: https://peps.python.org/pep-0661/
863+ Sentinel ( Sentinel ) ,
860864 /// Represents the result of a super() call. The first ClassType is the point in the MRO that attribute lookup
861865 /// on the super instance should start at (*not* the class passed to the super() call), and the second
862866 /// ClassType is the second argument (implicit or explicit) to the super() call. For example, in:
@@ -918,6 +922,7 @@ impl Visit for Type {
918922 Type :: Annotated ( x, _metadata) => x. visit ( f) ,
919923 Type :: Unpack ( x) => x. visit ( f) ,
920924 Type :: TypeVar ( x) => x. visit ( f) ,
925+ Type :: Sentinel ( x) => x. visit ( f) ,
921926 Type :: ParamSpec ( x) => x. visit ( f) ,
922927 Type :: TypeVarTuple ( x) => x. visit ( f) ,
923928 Type :: SpecialForm ( x) => x. visit ( f) ,
@@ -974,6 +979,7 @@ impl VisitMut for Type {
974979 Type :: Annotated ( x, _metadata) => x. visit_mut ( f) ,
975980 Type :: Unpack ( x) => x. visit_mut ( f) ,
976981 Type :: TypeVar ( x) => x. visit_mut ( f) ,
982+ Type :: Sentinel ( x) => x. visit_mut ( f) ,
977983 Type :: ParamSpec ( x) => x. visit_mut ( f) ,
978984 Type :: TypeVarTuple ( x) => x. visit_mut ( f) ,
979985 Type :: SpecialForm ( x) => x. visit_mut ( f) ,
@@ -1924,6 +1930,7 @@ impl Type {
19241930 Type :: ParamSpec ( t) => Some ( t. qname ( ) ) ,
19251931 Type :: SelfType ( cls) => Some ( cls. qname ( ) ) ,
19261932 Type :: Literal ( lit) if let Lit :: Enum ( e) = & lit. value => Some ( e. class . qname ( ) ) ,
1933+ Type :: Sentinel ( s) => Some ( s. qname ( ) ) ,
19271934 _ => None ,
19281935 }
19291936 }
@@ -1937,6 +1944,7 @@ impl Type {
19371944 Type :: Literal ( lit) if let Lit :: Str ( x) = & lit. value => Some ( !x. is_empty ( ) ) ,
19381945 Type :: Type ( _) => Some ( true ) ,
19391946 Type :: None => Some ( false ) ,
1947+ Type :: Sentinel ( _) => Some ( true ) ,
19401948 Type :: Tuple ( Tuple :: Concrete ( elements) ) => Some ( !elements. is_empty ( ) ) ,
19411949 Type :: Union ( u) => {
19421950 let mut answer = None ;
0 commit comments