Commits

Armin Rigo committed 7669c39

Simplify the code again, now that no_nul is a constructor argument.

Comments (0)

Files changed (1)

pypy/annotation/binaryop.py

         no_nul = str.no_nul
         for s_item in s_tuple.items:
             if isinstance(s_item, SomeFloat):
-                pass
+                pass   # or s_item is a subclass, like SomeInteger
             elif isinstance(s_item, SomeString) and s_item.no_nul:
                 pass
             else:
 
 # mixing Nones with other objects
 
-def _make_none_union(classname, constructor_args='', glob=None,
-                     copy_attributes=()):
-    if copy_attributes:
-        copy_attrs = (
-            'result.__dict__.update((name, getattr(obj, name)) '
-            'for name in %(copy_attributes)s if name in obj.__dict__)'
-            % locals())
-    else:
-        copy_attrs = ''
-
+def _make_none_union(classname, constructor_args='', glob=None):
     if glob is None:
         glob = globals()
     loc = locals()
         class __extend__(pairtype(%(classname)s, SomePBC)):
             def union((obj, pbc)):
                 if pbc.isNone():
-                    result = %(classname)s(%(constructor_args)s)
-                    %(copy_attrs)s
-                    return result
+                    return %(classname)s(%(constructor_args)s)
                 else:
                     return SomeObject()
 
         class __extend__(pairtype(SomePBC, %(classname)s)):
             def union((pbc, obj)):
                 if pbc.isNone():
-                    result = %(classname)s(%(constructor_args)s)
-                    %(copy_attrs)s
-                    return result
+                    return %(classname)s(%(constructor_args)s)
                 else:
                     return SomeObject()
     """ % loc)
     exec source.compile() in glob
 
 _make_none_union('SomeInstance',   'classdef=obj.classdef, can_be_None=True')
-_make_none_union('SomeString',      'can_be_None=True',
-                 copy_attributes=('no_nul',))
+_make_none_union('SomeString',      'no_nul=obj.no_nul, can_be_None=True')
 _make_none_union('SomeUnicodeString', 'can_be_None=True')
 _make_none_union('SomeList',         'obj.listdef')
 _make_none_union('SomeDict',          'obj.dictdef')
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.