Skip to content

Problems with some characters: [ ] { } ... #1606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
giorgio-denunzio opened this issue May 14, 2025 · 19 comments
Closed

Problems with some characters: [ ] { } ... #1606

giorgio-denunzio opened this issue May 14, 2025 · 19 comments

Comments

@giorgio-denunzio
Copy link

giorgio-denunzio commented May 14, 2025

Dear all,
I am getting mad how to figure this out.
Windows 11, Winpython64-3.13.3.0dot.7z.

I run "WinPython Command Prompt.exe".
At the prompt, with my Italian keyboard, I get:
"[" with "Alt Gr" + "è"
"]" with "Alt Gr" + "+"
"{" with "Alt Gr" + "Shift" + "è"
etc
I also get these characters and others with the usual sequences "Alt"+number keyboard, such as "Alt"+1,2,5 for "}", etc

I now enter python's shell by calling "python".
None of these sequences or key combination works anymore:
"Alt Gr" + "è" gives nothing but if I repeat it I get "["
"Alt Gr" + "+" gives nothing
If I want "]" I can do "Alt Gr" + "è" followed by "Alt Gr" + "+"
If I want "{" I can do "Alt Gr" + "è" followed by "Shift" + "Alt Gr" + "è"
If I want "}" I can do "Alt Gr" + "è" followed by "Shift" + "Alt Gr" + "+"

This happens only within python.
What is also strange is that I tried another portable python for Windows, with the same absurd result.
Edit: it also happens with an installable version.
Any hint?
Thanks
Giorgio
giorgio.denunzio@unisalento.it

@stonebig
Copy link
Contributor

It's a python-3.13.3 issue... when launched from a dos console

@stonebig
Copy link
Contributor

The issue was raised on cpython, already resolved I think on 3.14.0b1.
So either you launch python repl from the powershell console, either you wait python 3.13.4

@stonebig
Copy link
Contributor

Maybe it was OK on python-3.13.2 , also

@stonebig
Copy link
Contributor

stonebig commented May 15, 2025

fix for upcoming python-3.13.4: python/cpython#133460

issue was raised April 13th 2025 (only): python/cpython#132439

@stonebig stonebig added this to the 2025-03 PEP 751 / AI local milestone May 15, 2025
@giorgio-denunzio
Copy link
Author

Dear stonebig,
Thank you very much for your reply! So I had the “luck” of choosing version 3.13 😄
After reading your answer:

  • I tried launching WinPython Powershell Prompt.exe and then calling Python, but the problem is still there.
  • I also tried using the installed version by opening PowerShell and calling C:\Users\giorg\AppData\Local\Programs\Python\Python313\python.exe directly from the command line, but the issue persists.

Anyway, it’s not a big problem for now: I’ll simply download an older version and wait for 3.14.
Thanks again!
Best regards,
Giorgio

@stonebig
Copy link
Contributor

You are right, impossible to get it working... shame... so let see, just 7 lines to adjust... in your \python\Lib_pyrepl.py:

I'll do that for b2, but you may two... check lines with # GH-132439 pull 133460

Image

    def get_event(self, block: bool = True) -> Event | None:
        """Return an Event instance.  Returns None if |block| is false
        and there is no event pending, otherwise waits for the
        completion of an event."""
        if self.event_queue:
            return self.event_queue.pop()

        while True:
            rec = self._read_input(block)
            if rec is None:
                return None

            if rec.EventType == WINDOW_BUFFER_SIZE_EVENT:
                return Event("resize", "")

            if rec.EventType != KEY_EVENT or not rec.Event.KeyEvent.bKeyDown:
                # Only process keys and keydown events
                if block:
                    continue
                return None

            key_event = rec.Event.KeyEvent
            raw_key = key = key_event.uChar.UnicodeChar

            if key == "\r":
                # Make enter unix-like
                return Event(evt="key", data="\n")  # GH-132439 pull 133460
            elif key_event.wVirtualKeyCode == 8:
                # Turn backspace directly into the command
                key = "backspace"
            elif key == "\x00":
                # Handle special keys like arrow keys and translate them into the appropriate command
                key = VK_MAP.get(key_event.wVirtualKeyCode)
                if key:
                    if key_event.dwControlKeyState & CTRL_ACTIVE:
                        key = f"ctrl {key}"
                    elif key_event.dwControlKeyState & ALT_ACTIVE:
                        # queue the key, return the meta command
                        self.event_queue.insert(0, Event(evt="key", data=key))  # GH-132439 pull 133460
                        return Event(evt="key", data="\033")  # keymap.py uses this for meta
                    return Event(evt="key", data=key)  # GH-132439 pull 133460
                if block:
                    continue

                return None

            if key_event.dwControlKeyState & ALT_ACTIVE:
                # queue the key, return the meta command
                if not key_event.dwControlKeyState & CTRL_ACTIVE:  # GH-132439 pull 133460 
                    self.event_queue.insert(0, Event(evt="key", data=key))  # GH-132439 pull 133460 
                    return Event(evt="key", data="\033")  # GH-132439 pull 133460

            return Event(evt="key", data=key)  # GH-132439 pull 133460 

    def push_char(self, char: int | bytes) -> None:````

@stonebig stonebig reopened this May 18, 2025
@stonebig
Copy link
Contributor

waiting 15 days bugs me

@giorgio-denunzio
Copy link
Author

Congratulations :-)
Thanks for sharing!
Best,
Giorgio

@stonebig
Copy link
Contributor

stonebig commented May 18, 2025

NOT FULLY resolved in b2, binaries at:

@stonebig
Copy link
Contributor

well a=[ 1, 2] works, but not copy/paste of code

@stonebig stonebig reopened this May 21, 2025
@stonebig
Copy link
Contributor

stonebig commented May 21, 2025

So the "hammer" way WAS, is, to just copy from cpython-3.13 branch the inside lib\_pyrepl object that have changes since less than 2 month.

Trying to be smart was stupid

you can download at the same _pyrepl place all the 7 filesmodified since less than 2 month from https://github.com/python/cpython/tree/3.13/Lib/_pyrepl

Image

It works, did check on the copy/past of sudoku code in the console proofing

@giorgio-denunzio
Copy link
Author

Wow! When I opened the issue, I didn’t think I’d end up keeping you up at night! :-D
Congratulations!
Giorgio

@stonebig
Copy link
Contributor

stonebig commented May 21, 2025

nevertheless, copy.paste is wayyyy faster in 3.14 console... so it fixes but it's slow:

  • 8 seconds to paste 250 lines on 3.13 patched REPL
  • 0.5 second or less on 3.14 REPL

@stonebig
Copy link
Contributor

this is were you see there is way more WORKFORCE than before in cpython

@stonebig
Copy link
Contributor

stonebig commented May 21, 2025

in 3.13.1 , the copy paste WAS also that slow... and NOT WORKING.

so:

  • my patch was maybe correct
  • but 3.13.1 to 3.13.3 was not "copy/paste" friendly
  • it's really python-3.14.0 improvements

... feeling less stupid, but it was still not smart

@stonebig
Copy link
Contributor

also, current REPL in 3.14 b1:

  • on par with ptpython for copy/paste
  • still feels less stable and complete than ptpyhon.... but they stiil backport things, so issues raising may help after b2

@stonebig
Copy link
Contributor

stonebig commented May 26, 2025

the slowness of REPL on copy/past was raised in february... python/cpython#130328
a fix reached 3.14 yesterday python/cpython#134653
not sure the fix will reach 3.13 ... in theory it's more a bug than a feature.

@stonebig
Copy link
Contributor

as I was already faster when I took the 3.14, I suppose it comes from this that already speed-up things python/cpython#133247

@stonebig
Copy link
Contributor

stonebig commented May 26, 2025

no backport for the slowness problem .... so 3.13 will remain with ptpython when available.
for 3.14, we need to see what 3.14b2 brings in completion.

ptpython (and jedi) was a giant leap forward, I hope more of it will integrate the standard over time

wppm -p ptpython
          ptpython==3.0.29 ,
               appdirs==1.4.4
               jedi==0.19.2 >=0.16.0,
                    parso==0.8.4 (<0.9.0,>=0.8.4)
               prompt-toolkit==3.0.50 <3.1.0,>=3.0.43,
                    wcwidth==0.2.13
               pygments==2.19.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants