homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients benjamin.peterson, eryksun, methane, vstinner
Date 2014年03月27日.08:18:40
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1395908321.14.0.220618840205.issue21074@psf.upfronthosting.co.za>
In-reply-to
Content
Hi, I have a project called "astoptimizer" which does the same job than the CPython peephole optimizer, but it is implemented in Python.
To avoid this issue (create an huge object and then discard it because it is too large), I have a "check_binop_cst" function which checks if the result will fit into the configuration constraints:
https://bitbucket.org/haypo/astoptimizer/src/024c05ae410458813c20fafe8fe5b8d3cf980f52/astoptimizer/optimizer.py?at=default#cl-598
Check for "a * b" :
-------------
 if isinstance(op, ast.Mult):
 if isinstance(right, INT_TYPES):
 # str * int
 if isinstance(left, STR_TYPES):
 return (len(left) * right <= self.config.max_string_length)
 # tuple * int
 if isinstance(left, tuple):
 return (len(left) * right <= self.config.max_tuple_length)
 if isinstance(left, INT_TYPES):
 # int * str
 if isinstance(right, STR_TYPES):
 return (left * len(right) <= self.config.max_string_length)
 # int * tuple
 if isinstance(right, tuple):
 return (left * len(right) <= self.config.max_tuple_length)
-------------
Constraints in the config:
https://bitbucket.org/haypo/astoptimizer/src/024c05ae410458813c20fafe8fe5b8d3cf980f52/astoptimizer/config.py?at=default#cl-187
Astoptimizer supports the following "constant" types: int, float, complex, bytes, str, tuple, "name constant" (True, False, None). The frozenset type is also supported if the builtins are declared as "cosntant" too.
History
Date User Action Args
2014年03月27日 08:18:41vstinnersetrecipients: + vstinner, benjamin.peterson, methane, eryksun
2014年03月27日 08:18:41vstinnersetmessageid: <1395908321.14.0.220618840205.issue21074@psf.upfronthosting.co.za>
2014年03月27日 08:18:41vstinnerlinkissue21074 messages
2014年03月27日 08:18:40vstinnercreate

AltStyle によって変換されたページ (->オリジナル) /