File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -523,6 +523,32 @@ impl PyType {
523523 Ok ( ( ) )
524524 }
525525
526+ #[ pygetset( magic) ]
527+ fn annotations ( & self , vm : & VirtualMachine ) -> PyResult < PyObjectRef > {
528+ if !self . slots . flags . has_feature ( PyTypeFlags :: HEAPTYPE ) {
529+ return Err ( vm. new_attribute_error ( format ! (
530+ "type object '{}' has no attribute '__annotations__'" ,
531+ self . name( )
532+ ) ) ) ;
533+ }
534+
535+ let __annotations__ = identifier ! ( vm, __annotations__) ;
536+ let annotations = self . attributes . read ( ) . get ( __annotations__) . cloned ( ) ;
537+
538+ let annotations = if let Some ( annotations) = annotations {
539+ annotations
540+ } else {
541+ let annotations: PyObjectRef = vm. ctx . new_dict ( ) . into ( ) ;
542+ let removed = self
543+ . attributes
544+ . write ( )
545+ . insert ( __annotations__, annotations. clone ( ) ) ;
546+ debug_assert ! ( removed. is_none( ) ) ;
547+ annotations
548+ } ;
549+ Ok ( annotations)
550+ }
551+
526552 #[ pygetset( magic) ]
527553 pub fn module ( & self , vm : & VirtualMachine ) -> PyObjectRef {
528554 self . attributes
You can’t perform that action at this time.
0 commit comments