@@ -1809,6 +1809,8 @@ pub enum KnownInstanceType<'db> {
1809
1809
Literal ,
1810
1810
/// The symbol `typing.Optional` (which can also be found as `typing_extensions.Optional`)
1811
1811
Optional ,
1812
+ /// The symbol `typing.Union` (which can also be found as `typing_extensions.Union`)
1813
+ Union ,
1812
1814
/// A single instance of `typing.TypeVar`
1813
1815
TypeVar ( TypeVarInstance < ' db > ) ,
1814
1816
// TODO: fill this enum out with more special forms, etc.
@@ -1819,14 +1821,17 @@ impl<'db> KnownInstanceType<'db> {
1819
1821
match self {
1820
1822
KnownInstanceType :: Literal => "Literal" ,
1821
1823
KnownInstanceType :: Optional => "Optional" ,
1824
+ KnownInstanceType :: Union => "Union" ,
1822
1825
KnownInstanceType :: TypeVar ( _) => "TypeVar" ,
1823
1826
}
1824
1827
}
1825
1828
1826
1829
/// Evaluate the known instance in boolean context
1827
1830
pub const fn bool ( self ) -> Truthiness {
1828
1831
match self {
1829
- Self :: Literal | Self :: Optional | Self :: TypeVar ( _) => Truthiness :: AlwaysTrue ,
1832
+ Self :: Literal | Self :: Optional | Self :: TypeVar ( _) | Self :: Union => {
1833
+ Truthiness :: AlwaysTrue
1834
+ }
1830
1835
}
1831
1836
}
1832
1837
@@ -1835,6 +1840,7 @@ impl<'db> KnownInstanceType<'db> {
1835
1840
match self {
1836
1841
Self :: Literal => "typing.Literal" ,
1837
1842
Self :: Optional => "typing.Optional" ,
1843
+ Self :: Union => "typing.Union" ,
1838
1844
Self :: TypeVar ( typevar) => typevar. name ( db) ,
1839
1845
}
1840
1846
}
@@ -1844,6 +1850,7 @@ impl<'db> KnownInstanceType<'db> {
1844
1850
match self {
1845
1851
Self :: Literal => KnownClass :: SpecialForm ,
1846
1852
Self :: Optional => KnownClass :: SpecialForm ,
1853
+ Self :: Union => KnownClass :: SpecialForm ,
1847
1854
Self :: TypeVar ( _) => KnownClass :: TypeVar ,
1848
1855
}
1849
1856
}
@@ -1864,6 +1871,7 @@ impl<'db> KnownInstanceType<'db> {
1864
1871
match ( module. name ( ) . as_str ( ) , instance_name) {
1865
1872
( "typing" | "typing_extensions" , "Literal" ) => Some ( Self :: Literal ) ,
1866
1873
( "typing" | "typing_extensions" , "Optional" ) => Some ( Self :: Optional ) ,
1874
+ ( "typing" | "typing_extensions" , "Union" ) => Some ( Self :: Union ) ,
1867
1875
_ => None ,
1868
1876
}
1869
1877
}
0 commit comments