@@ -2,12 +2,15 @@ use super::{PyStrRef, PyType, PyTypeRef};
22use crate :: {
33 Context , Py , PyObjectRef , PyPayload , PyResult , VirtualMachine ,
44 class:: PyClassImpl ,
5+ common:: hash:: PyHash ,
56 convert:: ToPyObject ,
6- function:: FuncArgs ,
7+ function:: { FuncArgs , PyComparisonValue } ,
78 protocol:: PyNumberMethods ,
8- types:: { AsNumber , Constructor , Representable } ,
9+ types:: { AsNumber , Comparable , Constructor , Hashable , PyComparisonOp , Representable } ,
910} ;
1011
12+ const NONE_HASH : PyHash = 0xFCA8_6420 ;
13+
1114#[ pyclass( module = false , name = "NoneType" ) ]
1215#[ derive( Debug ) ]
1316pub struct PyNone ;
@@ -49,7 +52,7 @@ impl Constructor for PyNone {
4952 }
5053}
5154
52- #[ pyclass( with( Constructor , AsNumber , Representable ) ) ]
55+ #[ pyclass( with( Constructor , AsNumber , Comparable , Hashable , Representable ) ) ]
5356impl PyNone { }
5457
5558impl Representable for PyNone {
@@ -74,6 +77,26 @@ impl AsNumber for PyNone {
7477 }
7578}
7679
80+ impl Comparable for PyNone {
81+ fn cmp (
82+ zelf : & Py < Self > ,
83+ other : & crate :: PyObject ,
84+ op : PyComparisonOp ,
85+ _vm : & VirtualMachine ,
86+ ) -> PyResult < PyComparisonValue > {
87+ Ok ( op
88+ . identical_optimization ( zelf, other)
89+ . map ( PyComparisonValue :: Implemented )
90+ . unwrap_or ( PyComparisonValue :: NotImplemented ) )
91+ }
92+ }
93+
94+ impl Hashable for PyNone {
95+ fn hash ( _zelf : & Py < Self > , _vm : & VirtualMachine ) -> PyResult < PyHash > {
96+ Ok ( NONE_HASH )
97+ }
98+ }
99+
77100#[ pyclass( module = false , name = "NotImplementedType" ) ]
78101#[ derive( Debug ) ]
79102pub struct PyNotImplemented ;
0 commit comments