py3k flag used inappropriately to detect actual py3K, not just the warning

Issue #2348 resolved
Former user created an issue

"python2 -3" means "warn about Python 3.x incompatibilities that 2to3 cannot trivially fix"; it does not mean Python 3 syntax or features are supported.

Because the py3k variable gets set incorrectly, I get an exception later on, when Python 3 code is executed in Python 2.

I grepped and can't see any other occurrences of this mistake.

Comments (5)

  1. Mike Bayer repo owner

    that setting is intentional - "py3k" here means to run in such a way that the -3 flag will not generate any warnings - such as not using "sets.Set", not importing cPickle, the awkward workaround for callable(), etc. Actual Py3k-only-isms are rendered at the 2to3 level using custom directives.

    This is the patch you actually want:

    diff -r 34a5fafd6c38508f090344f435c73a19023bf0b2 lib/sqlalchemy/orm/collections.py
    --- a/lib/sqlalchemy/orm/collections.py Sun Dec 11 10:42:18 2011 -0500
    +++ b/lib/sqlalchemy/orm/collections.py Thu Dec 15 09:55:58 2011 -0500
    @@ -1166,11 +1166,12 @@
         l.pop('Unspecified')
         return l
    
    -if util.py3k:
    -    _set_binop_bases = (set, frozenset)
    -else:
    -    import sets
    -    _set_binop_bases = (set, frozenset, sets.BaseSet)
    +# Py3K
    +#_set_binop_bases = (set, frozenset)
    +# Py2K
    +import sets
    +_set_binop_bases = (set, frozenset, sets.BaseSet)
    +# end Py2K
    
     def _set_binops_check_strict(self, obj):
         """Allow only set, frozenset and self.__class__-derived objects in binops."""
    diff -r 34a5fafd6c38508f090344f435c73a19023bf0b2 lib/sqlalchemy/util/__init__.py
    --- a/lib/sqlalchemy/util/__init__.py   Sun Dec 11 10:42:18 2011 -0500
    +++ b/lib/sqlalchemy/util/__init__.py   Thu Dec 15 09:55:58 2011 -0500
    @@ -5,7 +5,7 @@
     # the MIT License: http://www.opensource.org/licenses/mit-license.php
    
     from compat import callable, cmp, reduce, defaultdict, py25_dict, \
    -    threading, py3k, jython, pypy, win32, set_types, buffer, pickle, \
    +    threading, py3k_warning, jython, pypy, win32, set_types, buffer, pickle, \
         update_wrapper, partial, md5_hex, decode_slice, dottedgetter,\
         parse_qsl
    
    diff -r 34a5fafd6c38508f090344f435c73a19023bf0b2 lib/sqlalchemy/util/compat.py
    --- a/lib/sqlalchemy/util/compat.py Sun Dec 11 10:42:18 2011 -0500
    +++ b/lib/sqlalchemy/util/compat.py Thu Dec 15 09:55:58 2011 -0500
    @@ -18,12 +18,12 @@
         import dummy_threading as threading
    
     py32 = sys.version_info >= (3, 2)
    -py3k = getattr(sys, 'py3kwarning', False) or sys.version_info >= (3, 0)
    +py3k_warning = getattr(sys, 'py3kwarning', False) or sys.version_info >= (3, 0)
     jython = sys.platform.startswith('java')
     pypy = hasattr(sys, 'pypy_version_info')
     win32 = sys.platform.startswith('win')
    
    -if py3k:
    +if py3k_warning:
         set_types = set
     elif sys.version_info < (2, 6):
         import sets
    @@ -43,7 +43,7 @@
    
         set_types = set, sets.Set
    
    -if py3k:
    +if py3k_warning:
         import pickle
     else:
         try:
    @@ -89,12 +89,13 @@
     else:
         from urlparse import parse_qsl
    
    -if py3k:
    -    from inspect import getfullargspec as inspect_getfullargspec
    -else:
    -    from inspect import getargspec as inspect_getfullargspec
    +# Py3k
    +# from inspect import getfullargspec as inspect_getfullargspec
    +# Py2K
    +from inspect import getargspec as inspect_getfullargspec
    +# end Py2K
    
    -if py3k:
    +if py3k_warning:
         # they're bringing it back in 3.2.  brilliant !
         def callable(fn):
             return hasattr(fn, '__call__')
    diff -r 34a5fafd6c38508f090344f435c73a19023bf0b2 lib/sqlalchemy/util/langhelpers.py
    --- a/lib/sqlalchemy/util/langhelpers.py    Sun Dec 11 10:42:18 2011 -0500
    +++ b/lib/sqlalchemy/util/langhelpers.py    Thu Dec 15 09:55:58 2011 -0500
    @@ -15,7 +15,7 @@
     import sys
     import types
     import warnings
    -from compat import update_wrapper, set_types, threading, callable, inspect_getfullargspec, py3k
    +from compat import update_wrapper, set_types, threading, callable, inspect_getfullargspec, py3k_warning
     from sqlalchemy import exc
    
     def _unique_symbols(used, *bases):
    @@ -162,20 +162,21 @@
         else:
             self_arg = None
    
    -    if py3k:
    -        apply_pos = inspect.formatargspec(spec[0](0), spec[1](1), spec[2](2), None, spec[4](4))
    -        num_defaults = 0
    -        if spec[3](3):
    -            num_defaults += len(spec[3](3))
    -        if spec[4](4):
    -            num_defaults += len(spec[4](4))
    -        name_args = spec[0](0) + spec[4](4)
    -    else:
    -        apply_pos = inspect.formatargspec(spec[0](0), spec[1](1), spec[2](2))
    -        num_defaults = 0
    -        if spec[3](3):
    -            num_defaults += len(spec[3](3))
    -        name_args = spec[0](0)
    +    # Py3K
    +    #apply_pos = inspect.formatargspec(spec[0](0), spec[1](1), spec[2](2), None, spec[4](4))
    +    #num_defaults = 0
    +    #if spec[3](3):
    +    #    num_defaults += len(spec[3](3))
    +    #if spec[4](4):
    +    #    num_defaults += len(spec[4](4))
    +    #name_args = spec[0](0) + spec[4](4)
    +    # Py2K
    +    apply_pos = inspect.formatargspec(spec[0](0), spec[1](1), spec[2](2))
    +    num_defaults = 0
    +    if spec[3](3):
    +        num_defaults += len(spec[3](3))
    +    name_args = spec[0](0)
    +    # end Py2K
    
         if num_defaults:
             defaulted_vals = name_args[0-num_defaults:](0-num_defaults:)
    diff -r 34a5fafd6c38508f090344f435c73a19023bf0b2 test/lib/testing.py
    --- a/test/lib/testing.py   Sun Dec 11 10:42:18 2011 -0500
    +++ b/test/lib/testing.py   Thu Dec 15 09:55:58 2011 -0500
    @@ -10,7 +10,7 @@
    
     from test.bootstrap import config
     from test.lib import assertsql, util as testutil
    -from sqlalchemy.util import py3k, decorator
    +from sqlalchemy.util import decorator
     from engines import drop_all_tables
    
     from sqlalchemy import exc as sa_exc, util, types as sqltypes, schema, \
    
  2. Log in to comment