Commit Graph

689 Commits

Author SHA1 Message Date
Yury Selivanov f2392133eb Issue #26110: Add LOAD_METHOD/CALL_METHOD opcodes.
Special thanks to INADA Naoki for pushing the patch through
the last mile, Serhiy Storchaka for reviewing the code, and to
Victor Stinner for suggesting the idea (originally implemented
in the PyPy project).
2016-12-13 19:03:51 -05:00
Serhiy Storchaka 0f6373c34f Issue #28739: f-string expressions no longer accepted as docstrings and
by ast.literal_eval() even if they do not include subexpressions.
2016-12-11 19:39:36 +02:00
Serhiy Storchaka 4cc30ae313 Issue #28739: f-string expressions no longer accepted as docstrings and
by ast.literal_eval() even if they do not include subexpressions.
2016-12-11 19:37:19 +02:00
Nick Coghlan d77e5b7211 Merge #23722 from 3.6 2016-12-05 16:59:22 +10:00
Nick Coghlan 19d246745d Issue #23722: improve __classcell__ compatibility
Handling zero-argument super() in __init_subclass__ and
__set_name__ involved moving __class__ initialisation to
type.__new__. This requires cooperation from custom
metaclasses to ensure that the new __classcell__ entry
is passed along appropriately.

The initial implementation of that change resulted in abruptly
broken zero-argument super() support in metaclasses that didn't
adhere to the new requirements (such as Django's metaclass for
Model definitions).

The updated approach adopted here instead emits a deprecation
warning for those cases, and makes them work the same way they
did in Python 3.5.

This patch also improves the related class machinery documentation
to cover these details and to include more reader-friendly
cross-references and index entries.
2016-12-05 16:47:55 +10:00
Serhiy Storchaka 3d85fae91f Issue #28823: Simplified compiling with opcode BUILD_MAP_UNPACK. 2016-11-28 20:56:37 +02:00
Serhiy Storchaka 85b0f5beb1 Added the const qualifier to char* variables that refer to readonly internal
UTF-8 represenatation of Unicode objects.
2016-11-20 10:16:47 +02:00
Serhiy Storchaka 3b73ea1278 Issue #28701: Replace PyUnicode_CompareWithASCIIString with _PyUnicode_EqualToASCIIString.
The latter function is more readable, faster and doesn't raise exceptions.
2016-11-16 10:19:20 +02:00
Serhiy Storchaka f4934ea77d Issue #28701: Replace PyUnicode_CompareWithASCIIString with _PyUnicode_EqualToASCIIString.
The latter function is more readable, faster and doesn't raise exceptions.
2016-11-16 10:17:58 +02:00
Serhiy Storchaka 7344285c19 Issue #28257: Improved error message when pass a non-iterable as
a var-positional argument.  Added opcode BUILD_TUPLE_UNPACK_WITH_CALL.
2016-10-02 10:33:46 +03:00
Serhiy Storchaka b72810583e Issue #27213: Fixed different issues with reworked CALL_FUNCTION* opcodes.
* BUILD_TUPLE_UNPACK and BUILD_MAP_UNPACK_WITH_CALL no longer generated with
  single tuple or dict.
* Restored more informative error messages for incorrect var-positional and
  var-keyword arguments.
* Removed code duplications in _PyEval_EvalCodeWithName().
* Removed redundant runtime checks and parameters in _PyStack_AsDict().
* Added a workaround and enabled previously disabled test in test_traceback.
* Removed dead code from the dis module.
2016-09-12 00:52:40 +03:00
Guido van Rossum 015d874626 Issue #28076: Variable annotations should be mangled for private names.
By Ivan Levkivskyi.
2016-09-11 09:45:24 -07:00
Serhiy Storchaka ab8740058a Issue #27129: Replaced wordcode related magic constants with macros. 2016-09-11 13:48:15 +03:00
Nick Coghlan 944368e1cc Issue #23722: Initialize __class__ from type.__new__()
The __class__ cell used by zero-argument super() is now initialized
from type.__new__ rather than __build_class__, so class methods
relying on that will now work correctly when called from metaclass
methods during class creation.

Patch by Martin Teichmann.
2016-09-11 14:45:49 +10:00
Victor Stinner f9b760f48a Rework CALL_FUNCTION* opcodes
Issue #27213: Rework CALL_FUNCTION* opcodes to produce shorter and more
efficient bytecode:

* CALL_FUNCTION now only accepts position arguments
* CALL_FUNCTION_KW accepts position arguments and keyword arguments, but keys
  of keyword arguments are packed into a constant tuple.
* CALL_FUNCTION_EX is the most generic, it expects a tuple and a dict for
  positional and keyword arguments.

CALL_FUNCTION_VAR and CALL_FUNCTION_VAR_KW opcodes have been removed.

2 tests of test_traceback are currently broken: skip test, the issue #28050 was
created to track the issue.

Patch by Demur Rumed, design by Serhiy Storchaka, reviewed by Serhiy Storchaka
and Victor Stinner.
2016-09-09 10:17:08 -07:00
Yury Selivanov 52c4e7cc84 Issue #28008: Implement PEP 530 -- asynchronous comprehensions. 2016-09-09 10:36:01 -07:00
Yury Selivanov eb6364557f Issue #28003: Implement PEP 525 -- Asynchronous Generators. 2016-09-08 22:01:51 -07:00
Yury Selivanov f8cb8a16a3 Issue #27985: Implement PEP 526 -- Syntax for Variable Annotations.
Patch by Ivan Levkivskyi.
2016-09-08 20:50:03 -07:00
Benjamin Peterson 2f8bfef158 replace PY_SIZE_MAX with SIZE_MAX 2016-09-07 09:26:18 -07:00
Benjamin Peterson ca47063998 replace Py_(u)intptr_t with the c99 standard types 2016-09-06 13:47:26 -07:00
Serhiy Storchaka ea525a2d1a Issue #27078: Added BUILD_STRING opcode. Optimized f-strings evaluation. 2016-09-06 22:07:53 +03:00
Ned Deily dc35cda2de Issue #27594: Prevent assertion error when running test_ast with coverage
enabled: ensure code object has a valid first line number.
Patch suggested by Ivan Levkivskyi.
2016-08-17 17:18:33 -04:00
Benjamin Peterson ce7b27d169 merge 3.5 (#27514) 2016-07-14 22:02:09 -07:00
Benjamin Peterson e09ed5419b make too many nested blocks be a SyntaxError instead of a SystemError (closes #27514)
Patch by Ammar Askar.
2016-07-14 22:00:03 -07:00
Serhiy Storchaka 607f8a5e28 Issue #27301: Fixed incorrect return codes for errors in compile.c. 2016-06-15 20:07:53 +03:00
Serhiy Storchaka 694de3bff7 Issue #27301: Fixed incorrect return codes for errors in compile.c. 2016-06-15 20:06:07 +03:00
Serhiy Storchaka 64204de04c Issue #27095: Simplified MAKE_FUNCTION and removed MAKE_CLOSURE opcodes.
Patch by Demur Rumed.
2016-06-12 17:36:24 +03:00
Serhiy Storchaka cf2ad55511 Issue #27286: Fixed compiling BUILD_MAP_UNPACK_WITH_CALL opcode. Calling
function with generalized unpacking (PEP 448) and conflicting keyword names
could cause undefined behavior.
2016-06-12 09:35:13 +03:00
Serhiy Storchaka 3c317e76a2 Issue #27286: Fixed compiling BUILD_MAP_UNPACK_WITH_CALL opcode. Calling
function with generalized unpacking (PEP 448) and conflicting keyword names
could cause undefined behavior.
2016-06-12 09:22:01 +03:00
Serhiy Storchaka 6a7506a77f Issue #27140: Added BUILD_CONST_KEY_MAP opcode. 2016-06-12 00:39:41 +03:00
Serhiy Storchaka b0f80b0312 Issue #26647: Python interpreter now uses 16-bit wordcode instead of bytecode.
Patch by Demur Rumed.
2016-05-24 09:15:14 +03:00
Serhiy Storchaka ec39756960 Issue #22570: Renamed Py_SETREF to Py_XSETREF. 2016-04-06 09:50:03 +03:00
Serhiy Storchaka 48842714b9 Issue #22570: Renamed Py_SETREF to Py_XSETREF. 2016-04-06 09:45:48 +03:00
Victor Stinner 976bb4099c compiler.c: fix compiler warnings on Windows 2016-03-23 11:36:19 +01:00
Victor Stinner 2ad474ba5e Update assertion in compiler_addop_i()
In practice, bytecode instruction arguments are unsigned. Update the assertion
to make it more explicit that argument must be greater or equal than 0.

Rewrite also the comment.
2016-03-01 23:34:47 +01:00
Victor Stinner fc6f2efd13 compile.c: inline compiler_use_new_block()
* Inline compiler_use_new_block() function into its only callee,
  compiler_enter_scope()
* Remove unused NEW_BLOCK() macro
2016-02-27 02:19:22 +01:00
Victor Stinner 15a3095d64 compiler: don't emit SyntaxWarning on const stmt
Issue #26204: the compiler doesn't emit SyntaxWarning warnings anymore when
constant statements are ignored.
2016-02-08 22:45:06 +01:00
Victor Stinner a2724095cd compiler now ignores constant statements
The compile ignores constant statements and emit a SyntaxWarning warning.

Don't emit the warning for string statement because triple quoted string is a
common syntax for multiline comments.

Don't emit the warning on ellipis neither: 'def f(): ...' is a legit syntax for
abstract functions.

Changes:

* test_ast: ignore SyntaxWarning when compiling test statements. Modify
  test_load_const() to use assignment expressions rather than constant
  expression.
* test_code: add more kinds of constant statements, ignore SyntaxWarning when
  testing that the compiler removes constant statements.
* test_grammar: ignore SyntaxWarning on the statement "1"
2016-02-08 18:17:58 +01:00
Victor Stinner f2c1aa1661 Add ast.Constant
Issue #26146: Add a new kind of AST node: ast.Constant. It can be used by
external AST optimizers, but the compiler does not emit directly such node.

An optimizer can replace the following AST nodes with ast.Constant:

* ast.NameConstant: None, False, True
* ast.Num: int, float, complex
* ast.Str: str
* ast.Bytes: bytes
* ast.Tuple if items are constants too: tuple
* frozenset

Update code to accept ast.Constant instead of ast.Num and/or ast.Str:

* compiler
* docstrings
* ast.literal_eval()
* Tools/parser/unparse.py
2016-01-26 00:40:57 +01:00
Victor Stinner efb2413ce8 code_richcompare() now uses the constants types
Issue #25843: When compiling code, don't merge constants if they are equal but
have a different types. For example, "f1, f2 = lambda: 1, lambda: 1.0" is now
correctly compiled to two different functions: f1() returns 1 (int) and f2()
returns 1.0 (int), even if 1 and 1.0 are equal.

Add a new _PyCode_ConstantKey() private function.
2016-01-22 12:33:12 +01:00
Victor Stinner f3914eb16d co_lnotab supports negative line number delta
Issue #26107: The format of the co_lnotab attribute of code objects changes to
support negative line number delta.

Changes:

* assemble_lnotab(): if line number delta is less than -128 or greater than
  127, emit multiple (offset_delta, lineno_delta) in co_lnotab
* update functions decoding co_lnotab to use signed 8-bit integers

  - dis.findlinestarts()
  - PyCode_Addr2Line()
  - _PyCode_CheckLineNumber()
  - frame_setlineno()

* update lnotab_notes.txt
* increase importlib MAGIC_NUMBER to 3361
* document the change in What's New in Python 3.6
* cleanup also PyCode_Optimize() to use better variable names
2016-01-20 12:16:21 +01:00
Serhiy Storchaka f006940351 Issue #20440: Massive replacing unsafe attribute setting code with special
macro Py_SETREF.
2015-12-24 10:39:57 +02:00
Serhiy Storchaka 5a57ade58e Issue #20440: Massive replacing unsafe attribute setting code with special
macro Py_SETREF.
2015-12-24 10:35:59 +02:00
Eric V. Smith a78c7954d5 Issue 25483: Add an opcode to make f-string formatting more robust. 2015-11-03 12:45:05 -05:00
Martin Panter e56a919100 Issue #25523: Merge a-to-an corrections from 3.5 2015-11-02 04:27:17 +00:00
Martin Panter 2eb819f7a8 Issue #25523: Merge "a" to "an" fixes from 3.4 into 3.5 2015-11-02 04:04:57 +00:00
Martin Panter 7462b64911 Issue #25523: Correct "a" article to "an" article
This changes the main documentation, doc strings, source code comments, and a
couple error messages in the test suite. In some cases the word was removed
or edited some other way to fix the grammar.
2015-11-02 03:37:02 +00:00
Eric V. Smith 235a6f0984 Issue #24965: Implement PEP 498 "Literal String Interpolation". Documentation is still needed, I'll open an issue for that. 2015-09-19 14:51:32 -04:00
Benjamin Peterson 7920b7063d merge 3.5 (#25060) 2015-09-10 21:11:26 -07:00
Benjamin Peterson b685515039 compute stack effect of BUILD_MAP correctly (closes #25060) 2015-09-10 21:02:39 -07:00
Stefan Krah ff9fe230d0 Fix refleak. 2015-07-27 12:57:21 +02:00
Stefan Krah c0cbed1554 Fix refleak. 2015-07-27 12:56:49 +02:00
Yury Selivanov 6d35043e49 Merge 3.5 (Issue #24687) 2015-07-23 09:11:13 +03:00
Yury Selivanov f315c1c016 Issue #24687: Plug refleak on SyntaxError in function parameters annotations. 2015-07-23 09:10:44 +03:00
Yury Selivanov 0811c5d7ba Merge 3.5 (Issue #24619) 2015-07-22 14:49:13 +03:00
Yury Selivanov b7666a3093 Issue #24619: More tests; fix nits in compiler.c 2015-07-22 14:48:57 +03:00
Yury Selivanov 3bd2b98c29 Merge 3.5 (Issue #24528) 2015-06-30 12:49:18 -04:00
Yury Selivanov 9dec03571f Issue #24528: Improve error message for awaits in comprehensions 2015-06-30 12:49:04 -04:00
Yury Selivanov 6edc2f7549 Issue #24400: Merge 3.5 2015-06-22 12:31:24 -04:00
Yury Selivanov 5376ba9630 Issue #24400: Introduce a distinct type for 'async def' coroutines.
Summary of changes:

1. Coroutines now have a distinct, separate from generators
   type at the C level: PyGen_Type, and a new typedef PyCoroObject.
   PyCoroObject shares the initial segment of struct layout with
   PyGenObject, making it possible to reuse existing generators
   machinery.  The new type is exposed as 'types.CoroutineType'.

   As a consequence of having a new type, CO_GENERATOR flag is
   no longer applied to coroutines.

2. Having a separate type for coroutines made it possible to add
   an __await__ method to the type.  Although it is not used by the
   interpreter (see details on that below), it makes coroutines
   naturally (without using __instancecheck__) conform to
   collections.abc.Coroutine and collections.abc.Awaitable ABCs.

   [The __instancecheck__ is still used for generator-based
   coroutines, as we don't want to add __await__ for generators.]

3. Add new opcode: GET_YIELD_FROM_ITER.  The opcode is needed to
   allow passing native coroutines to the YIELD_FROM opcode.

   Before this change, 'yield from o' expression was compiled to:

      (o)
      GET_ITER
      LOAD_CONST
      YIELD_FROM

   Now, we use GET_YIELD_FROM_ITER instead of GET_ITER.

   The reason for adding a new opcode is that GET_ITER is used
   in some contexts (such as 'for .. in' loops) where passing
   a coroutine object is invalid.

4. Add two new introspection functions to the inspec module:
   getcoroutinestate(c) and getcoroutinelocals(c).

5. inspect.iscoroutine(o) is updated to test if 'o' is a native
   coroutine object.  Before this commit it used abc.Coroutine,
   and it was requested to update inspect.isgenerator(o) to use
   abc.Generator; it was decided, however, that inspect functions
   should really be tailored for checking for native types.

6. sys.set_coroutine_wrapper(w) API is updated to work with only
   native coroutines.  Since types.coroutine decorator supports
   any type of callables now, it would be confusing that it does
   not work for all types of coroutines.

7. Exceptions logic in generators C implementation was updated
   to raise clearer messages for coroutines:

   Before: TypeError("generator raised StopIteration")
   After: TypeError("coroutine raised StopIteration")
2015-06-22 12:19:30 -04:00
Serhiy Storchaka ec466a15d9 Fixed indentation of Python examples in C comments. 2015-06-11 00:09:32 +03:00
Serhiy Storchaka 553e156921 Fixed indentation of Python examples in C comments. 2015-06-11 00:07:47 +03:00
Serhiy Storchaka d741a88049 Fixed indentation of Python examples in C comments. 2015-06-11 00:06:39 +03:00
Benjamin Peterson 264be6f48f remove STORE_MAP, since it's unused 2015-05-28 14:40:08 -05:00
Benjamin Peterson ee85339cc6 in dict displays, evaluate the key before the value (closes #11205)
Patch partially by Steve Dougherty.
2015-05-28 14:30:26 -05:00
Yury Selivanov 7544508f02 PEP 0492 -- Coroutines with async and await syntax. Issue #24017. 2015-05-11 22:57:16 -04:00
Benjamin Peterson 95283fb589 Merge 3.4 2015-05-07 18:42:16 -04:00
Benjamin Peterson 9e77f72fb2 shorten capsule name macro; it doesn't need to be so long 2015-05-07 18:41:47 -04:00
Benjamin Peterson 025e9ebd0a PEP 448: additional unpacking generalizations (closes #2292)
Patch by Neil Girdhar.
2015-05-05 20:16:41 -04:00
Benjamin Peterson 1dfd247c1b remove the concept of an unoptimized function scope from the compiler, since it can't happen anymore 2015-04-27 21:44:22 -04:00
Serhiy Storchaka 91427733ea Issue #23192: Fixed generator lambdas. Patch by Bruno Cauet. 2015-03-11 18:22:29 +02:00
Serhiy Storchaka c775ad615a Issue #23192: Fixed generator lambdas. Patch by Bruno Cauet. 2015-03-11 18:20:35 +02:00
Benjamin Peterson 7ced53cc63 merge 3.4 (#23048) 2014-12-13 16:08:15 -05:00
Benjamin Peterson 3cda0ed062 pop the loop block even for infinite while loops (closes #23048) 2014-12-13 16:06:19 -05:00
Nick Coghlan d600951748 Issue #22869: Split pythonrun into two modules
- interpreter startup and shutdown code moved to a new
  pylifecycle.c module
- Py_OptimizeFlag moved into the new module with the other
  global flags
2014-11-20 21:39:37 +10:00
Serhiy Storchaka df4518ca4b Issue #22453: Removed non-documented macro PyObject_REPR(). 2014-11-18 23:34:33 +02:00
Serhiy Storchaka 81f68a7d4b Issue #22453: Warn against the use of leaking macro PyObject_REPR(). 2014-11-19 00:08:38 +02:00
Antoine Pitrou e7811fca5e Closes #11471: avoid generating a JUMP_FORWARD instruction at the end of an if-block if there is no else-clause.
Original patch by Eugene Toder.
2014-09-18 03:06:50 +02:00
Antoine Pitrou 5c8008e59d Issue #21523: Fix over-pessimistic computation of the stack effect of some opcodes in the compiler.
This also fixes a quadratic compilation time issue noticeable when compiling
code with a large number of "and" and "or" operators.
2014-05-23 11:47:32 +02:00
Antoine Pitrou 9961405ed1 Issue #21523: Fix over-pessimistic computation of the stack effect of some opcodes in the compiler.
This also fixes a quadratic compilation time issue noticeable when compiling
code with a large number of "and" and "or" operators.
2014-05-23 11:46:03 +02:00
Benjamin Peterson d51374ed78 PEP 465: a dedicated infix operator for matrix multiplication (closes #21176) 2014-04-09 23:55:56 -04:00
Victor Stinner 065efc3072 Issue #20625: Fix compilation issue 2014-02-18 22:07:56 +01:00
Yury Selivanov 34ce99f66d Mangle __parameters in __annotations__ dict properly. Issue #20625. 2014-02-18 12:49:41 -05:00
Victor Stinner 6acc5e1330 Issue #20625: Fix compilation issue 2014-02-18 22:07:56 +01:00
Yury Selivanov 026019f89b Mangle __parameters in __annotations__ dict properly. Issue #20625. 2014-02-18 12:49:41 -05:00
Christian Heimes 724b828e79 upcast int to size_t to silence two autological-constant-out-of-range-compare warnings with clang. 2013-12-04 08:42:46 +01:00
Larry Hastings 3a9079742f Issue #19722: Added opcode.stack_effect(), which accurately
computes the stack effect of bytecode instructions.
2013-11-23 14:49:22 -08:00
Victor Stinner f8e3221fa5 Issue #9566, #19617: Fix more compiler warnings in compile.c on Windows 64-bit 2013-11-19 23:56:34 +01:00
Victor Stinner 85fe8a645e Issue #9566, #19617: New try to fix compilation on Windows
Some compilers (ex: Visual Studio) decode -2147483648 as a unsigned integer
instead of an signed integer.
2013-11-19 23:03:25 +01:00
Victor Stinner b679a2eb78 Issue #9566, #19617: Fix compilation on Windows
INT32_MIN and INT32_MAX constants are unknown on Windows.
2013-11-19 22:28:01 +01:00
Victor Stinner ad9a066050 Issue #9566: compile.c uses Py_ssize_t instead of int to store sizes to fix
compiler warnings on Windows 64-bit. Use Py_SAFE_DOWNCAST() where the final
downcast is needed.

The bytecode doesn't support integer parameters larger than 32-bit yet.
2013-11-19 22:23:20 +01:00
Victor Stinner 98e818b8e3 Issue #19437: Fix compiler_class(), handle compiler_lookup_arg() failure 2013-11-05 18:07:34 +01:00
Benjamin Peterson 6b4f7803f8 cleanup the construction of __qualname__ (closes #19301 again) 2013-10-20 17:50:28 -04:00
Nick Coghlan 6de9200e57 Close #19313: remove no longer needed Py_XINCREF
Eliminates a refleak introduced in commit b4a325275fb0
2013-10-20 22:43:53 +10:00
Benjamin Peterson 34d33a595b removal u_qualname, since compiler_scope_qualname is only ever called once 2013-10-19 16:15:58 -04:00
Benjamin Peterson a8a38b8e4f strengthen condition and add assertion 2013-10-19 16:14:39 -04:00
Benjamin Peterson 3d9e481ece give explicitly global functions and classes a global __qualname__ (closes #19301) 2013-10-19 16:01:13 -04:00
Serhiy Storchaka 46e1ce214b Issue #18783: Removed existing mentions of Python long type in docstrings,
error messages and comments.
2013-08-27 20:17:03 +03:00
Serhiy Storchaka 9594942716 Issue #18783: Removed existing mentions of Python long type in docstrings,
error messages and comments.
2013-08-27 19:40:23 +03:00
Victor Stinner 14e461d5b9 Close #11619: The parser and the import machinery do not encode Unicode
filenames anymore on Windows.
2013-08-26 22:28:21 +02:00