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 Antony.Lee
Recipients Antony.Lee, scoder
Date 2018-02-25.09:30:02
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1519551003.19.0.467229070634.issue32945@psf.upfronthosting.co.za>
In-reply-to
Content
Feel free to close the issue if that's not the forum for this discussion, but I'm still baffled by what's happening.

In the example that you give, the first case needs to look up the `list` global and that callable (which happens to be the `list` type) needs to figure out what to do with generator passed in.  Indeed, we can compare

    In [22]: dis.dis(compile("[i for i in [1, 2]]", "<string>", "single"))
  1           0 LOAD_CONST               0 (<code object <listcomp> at 0x7f2d3237ec00, file "<string>", line 1>)
              2 LOAD_CONST               1 ('<listcomp>')
              4 MAKE_FUNCTION            0
              6 LOAD_CONST               5 ((1, 2))
              8 GET_ITER
             10 CALL_FUNCTION            1
             12 PRINT_EXPR
             14 LOAD_CONST               4 (None)
             16 RETURN_VALUE

In [23]: dis.dis(compile("list(i for i in [1, 2])", "<string>", "single"))
  1           0 LOAD_NAME                0 (list)
              2 LOAD_CONST               0 (<code object <genexpr> at 0x7f2d32392150, file "<string>", line 1>)
              4 LOAD_CONST               1 ('<genexpr>')
              6 MAKE_FUNCTION            0
              8 LOAD_CONST               5 ((1, 2))
             10 GET_ITER
             12 CALL_FUNCTION            1
             14 CALL_FUNCTION            1
             16 PRINT_EXPR
             18 LOAD_CONST               4 (None)
             20 RETURN_VALUE

Note how the latter has an extra function call (to `list`).

In the example I gave, however:

    In [24]: dis.dis(compile("sorted([i for i in [1, 2]])", "<string>", "single"))
    1           0 LOAD_NAME                0 (sorted)
                2 LOAD_CONST               0 (<code object <listcomp> at 0x7f2d3231eb70, file "<string>", line 1>)
                4 LOAD_CONST               1 ('<listcomp>')
                6 MAKE_FUNCTION            0
                8 LOAD_CONST               5 ((1, 2))
                10 GET_ITER
                12 CALL_FUNCTION            1
                14 CALL_FUNCTION            1
                16 PRINT_EXPR
                18 LOAD_CONST               4 (None)
                20 RETURN_VALUE

    In [25]: dis.dis(compile("sorted(i for i in [1, 2])", "<string>", "single"))
    1           0 LOAD_NAME                0 (sorted)
                2 LOAD_CONST               0 (<code object <genexpr> at 0x7f2d32328930, file "<string>", line 1>)
                4 LOAD_CONST               1 ('<genexpr>')
                6 MAKE_FUNCTION            0
                8 LOAD_CONST               5 ((1, 2))
                10 GET_ITER
                12 CALL_FUNCTION            1
                14 CALL_FUNCTION            1
                16 PRINT_EXPR
                18 LOAD_CONST               4 (None)
                20 RETURN_VALUE

so both cases are much more similar -- superficially, at least.
History
Date User Action Args
2018-02-25 09:30:03Antony.Leesetrecipients: + Antony.Lee, scoder
2018-02-25 09:30:03Antony.Leesetmessageid: <1519551003.19.0.467229070634.issue32945@psf.upfronthosting.co.za>
2018-02-25 09:30:03Antony.Leelinkissue32945 messages
2018-02-25 09:30:02Antony.Leecreate