mirror of
				https://github.com/LonamiWebs/Telethon.git
				synced 2025-11-04 01:47:27 +03:00 
			
		
		
		
	Make .to_dict() work on invalid TLObjects
This will improve logging from the previous commit as well.
This commit is contained in:
		
							parent
							
								
									d3efc8f57d
								
							
						
					
					
						commit
						f25541ea6f
					
				| 
						 | 
					@ -54,7 +54,11 @@ def _write_modules(
 | 
				
			||||||
                SourceBuilder(f) as builder:
 | 
					                SourceBuilder(f) as builder:
 | 
				
			||||||
            builder.writeln(AUTO_GEN_NOTICE)
 | 
					            builder.writeln(AUTO_GEN_NOTICE)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            builder.writeln('from {}.tl.tlobject import {}', '.' * depth, kind)
 | 
					            builder.writeln('from {}.tl.tlobject import TLObject', '.' * depth)
 | 
				
			||||||
 | 
					            if kind != 'TLObject':
 | 
				
			||||||
 | 
					                builder.writeln(
 | 
				
			||||||
 | 
					                    'from {}.tl.tlobject import {}', '.' * depth, kind)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            builder.writeln('from typing import Optional, List, '
 | 
					            builder.writeln('from typing import Optional, List, '
 | 
				
			||||||
                            'Union, TYPE_CHECKING')
 | 
					                            'Union, TYPE_CHECKING')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -296,13 +300,14 @@ def _write_to_dict(tlobject, builder):
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            if arg.is_vector:
 | 
					            if arg.is_vector:
 | 
				
			||||||
                builder.write(
 | 
					                builder.write(
 | 
				
			||||||
                    '[] if self.{0} is None else [None '
 | 
					                    '[] if self.{0} is None else [x.to_dict() '
 | 
				
			||||||
                    'if x is None else x.to_dict() for x in self.{0}]',
 | 
					                    'if isinstance(x, TLObject) else x for x in self.{0}]',
 | 
				
			||||||
                    arg.name
 | 
					                    arg.name
 | 
				
			||||||
                )
 | 
					                )
 | 
				
			||||||
            else:
 | 
					            else:
 | 
				
			||||||
                builder.write(
 | 
					                builder.write(
 | 
				
			||||||
                    'None if self.{0} is None else self.{0}.to_dict()',
 | 
					                    'self.{0}.to_dict() '
 | 
				
			||||||
 | 
					                    'if isinstance(self.{0}, TLObject) else self.{0}',
 | 
				
			||||||
                    arg.name
 | 
					                    arg.name
 | 
				
			||||||
                )
 | 
					                )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user