On 4/13/21 3:28 PM, Terry Reedy wrote:
On 4/13/2021 4:21 AM, Baptiste Carvello wrote:
Le 12/04/2021 à 03:55, Larry Hastings a écrit :
- in section "Interactive REPL Shell":
For the sake of simplicity, in this case we forego delayed evaluation.
The intention of the code + codeop modules is that people should be able to write interactive consoles that simulate the standard REPL. For example:
Python 3.10.0a7+ (heads/master-dirty:a9cf69df2e, Apr 12 2021, 15:36:39) [MSC v.1900 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information.
import code code.interact()
Python 3.10.0a7+ (heads/master-dirty:a9cf69df2e, Apr 12 2021, 15:36:39) [MSC v.1900 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole)
# Call has not returned. Prompt is from code.InteractiveConsole. def f(x:int): -> float
f.__annotations__ # should match REPL result
now exiting InteractiveConsole...
Now back to repl
If the REPL compiles with "mode='single' and spec is changes to "when mode is 'single'", then above should work. Larry, please test with your proposed implementation.
A couple things!
1. I apologize if the PEP wasn't clear, but this section was talking about the problem of /module/ annotations in the implicit __main__ module when using the interactive REPL. Annotations on other objects (classes, functions, etc) defined in the interactive REPL work as expected. 2. The above example has a minor bug: when defining a return annotation on a function, the colon ending the function declaration goes /after/ the return annotation. It should have been "def f(x:int) -> float:". 3. The above example works fine when run in my branch. 4. You need to "from __future__ import co_annotations" in order to activate delayed evaluation of annotations using code objects in my branch. I added that (inside the code.interact() shell!) and it still works fine.
So I'm not sure what problem you're proposing to solve with this "mode is single" stuff.
* If you thought there was a problem with defining annotations on functions and classes defined in the REPL, good news!, it was never a problem. * If you're solving the problem of defining annotations on the interactive module /itself,/ I don't understand what your proposed solution is or how it would work. The problem is, how do you create a code object that defines all the annotations on a module, when the module never finishes being defined because it's the interactive shell?