File tree Expand file tree Collapse file tree 4 files changed +84
-2
lines changed Expand file tree Collapse file tree 4 files changed +84
-2
lines changed Original file line number Diff line number Diff line change 2222            task : make -f Makefile yamllint 
2323          - dependencies : > 
2424              bandit 
25+               monkeytype 
2526              pylint 
2627              python3-dbus 
2728              python3-dbus-signature-pyparsing 
Original file line number Diff line number Diff line change @@ -9,9 +9,11 @@ MONKEYTYPE_MODULES = into_dbus_python._signature
99.PHONY : lint
1010lint :
1111	pylint setup.py
12+ 	pylint monkeytype_config.py
1213	pylint src/into_dbus_python
1314	pylint tests
1415	bandit setup.py
16+ 	bandit monkeytype_config.py
1517	#  Ignore B101 errors. We do not distribute optimized code, i.e., .pyo
1618	#  files in Fedora, so we do not need to have concerns that assertions
1719	#  are removed by optimization.
@@ -31,7 +33,7 @@ coverage:
3133
3234.PHONY : fmt
3335fmt :
34- 	isort setup.py src tests
36+ 	isort setup.py src tests monkeytype_config.py 
3537	black . 
3638
3739.PHONY : fmt-travis
Original file line number Diff line number Diff line change 1+ """ 
2+ Monkeytype Configuration File 
3+ """ 
4+ 
5+ # isort: STDLIB 
6+ from  typing  import  Any , Union 
7+ 
8+ # isort: THIRDPARTY 
9+ from  monkeytype .config  import  DefaultConfig 
10+ from  monkeytype .typing  import  (
11+     ChainedRewriter ,
12+     RemoveEmptyContainers ,
13+     RewriteConfigDict ,
14+     RewriteGenerator ,
15+     RewriteLargeUnion ,
16+     TypeRewriter ,
17+ )
18+ 
19+ 
20+ class  CanonicalizeUnionElementOrder (TypeRewriter ):
21+     """ 
22+     Monkeytype type rewriter to sort union elements in canonical order. 
23+     """ 
24+ 
25+     @staticmethod  
26+     def  type_order (typ ) ->  str :
27+         """ 
28+         Return a value to be used as a key for sorting. 
29+         """ 
30+ 
31+         print (f"BIG: { typ }  , flush = True )
32+         if  typ  is  Any :
33+             return  "Any" 
34+ 
35+         try :
36+             under_name  =  typ ._name   # pylint: disable=protected-access 
37+         except  AttributeError :
38+             under_name  =  None 
39+ 
40+         try :
41+             dunder_name  =  typ .__name__ 
42+         except  AttributeError :
43+             dunder_name  =  None 
44+ 
45+         return  (
46+             under_name 
47+             if  under_name  is  not None 
48+             else  (dunder_name  if  dunder_name  is  not None  else  "" )
49+         )
50+ 
51+     def  rewrite_Union (self , union ):
52+         return  Union [
53+             tuple (
54+                 sorted (
55+                     list (union .__args__ ),
56+                     key = CanonicalizeUnionElementOrder .type_order ,
57+                 )
58+             )
59+         ]
60+ 
61+ 
62+ class  MyConfig (DefaultConfig ):
63+     """ 
64+     Monkeytype configuration for this project 
65+     """ 
66+ 
67+     def  type_rewriter (self ):
68+         return  ChainedRewriter (
69+             (
70+                 RemoveEmptyContainers (),
71+                 RewriteConfigDict (),
72+                 RewriteLargeUnion (),
73+                 RewriteGenerator (),
74+                 CanonicalizeUnionElementOrder (),
75+             )
76+         )
77+ 
78+ 
79+ CONFIG  =  MyConfig ()
Original file line number Diff line number Diff line change @@ -299,7 +299,7 @@ def __init__(self):
299299_XFORMER  =  _ToDbusXformer ()
300300
301301
302- def  xformers (sig : str ) ->  List [Union [Tuple [Callable , str ],  Any ]]:
302+ def  xformers (sig : str ) ->  List [Union [Any ,  Tuple [Callable , str ]]]:
303303    """ 
304304    Get the list of xformer functions for the given signature. 
305305
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments