[issue40897] Inheriting from class that defines __new__ causes inspect.signature to always return (*args, **kwargs) for constructor
Jonathan Slenders added the comment: The following patch to inspect.py solves the issue that inspect.signature() returns the wrong signature on classes that inherit from Generic. Not 100% sure though if this implementation is the cleanest way possible. I've been looking into attaching a __wrapped__ to Generic as well, without success. I'm not very familiar with the inspect code. To me, this fix is pretty important. ptpython, a Python REPL, has the ability to show the function signature of what the user is currently typing, and with codebases that have lots of generics, there's nothing really useful we can show. $ diff inspect.old.py inspect.py -p *** inspect.old.py 2021-02-17 11:35:50.787234264 +0100 --- inspect.py 2021-02-17 11:35:10.131407202 +0100 *** import sys *** 44,49 --- 44,50 import tokenize import token import types + import typing import warnings import functools import builtins *** def _signature_get_user_defined_method(c *** 1715,1720 --- 1716,1725 except AttributeError: return else: + if meth in (typing.Generic.__new__, typing.Protocol.__new__): + # Exclude methods from the typing module. + return + if not isinstance(meth, _NonUserDefinedCallables): # Once '__signature__' will be added to 'C'-level # callables, this check won't be necessary *** For those interested, the following monkey-patch has the same effect: def monkey_patch_typing() -> None: import inspect, typing def _signature_get_user_defined_method(cls, method_name): try: meth = getattr(cls, method_name) except AttributeError: return else: if meth in (typing.Generic.__new__, typing.Protocol.__new__): # Exclude methods from the typing module. return if not isinstance(meth, inspect._NonUserDefinedCallables): # Once '__signature__' will be added to 'C'-level # callables, this check won't be necessary return meth inspect._signature_get_user_defined_method = _signature_get_user_defined_method monkey_patch_typing() -- nosy: +jonathan.slenders ___ Python tracker <https://bugs.python.org/issue40897> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue39010] ProactorEventLoop raises unhandled ConnectionResetError
Jonathan Slenders added the comment: Even simpler, the following code will crash after so many iterations: ``` import asyncio loop = asyncio.get_event_loop() while True: loop.call_soon_threadsafe(loop.stop) loop.run_forever() ``` Adding a little sleep of 0.01s after `run_forever()` prevents the issue. So, to me it looks like the cancellation of the `_OverlappedFuture` that wraps around the `_recv()` call from the self-pipe did not complete before we start `_recv()` again in the next `run_forever()` call. No idea if that makes sense... -- ___ Python tracker <https://bugs.python.org/issue39010> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue39010] ProactorEventLoop raises unhandled ConnectionResetError
Jonathan Slenders added the comment: It looks like the following code will reproduce the issue: ``` import asyncio import threading loop = asyncio.get_event_loop() while True: def test(): loop.call_soon_threadsafe(loop.stop) threading.Thread(target=test).start() loop.run_forever() ``` Leave it running on Windows, in Python 3.8 for a few seconds, then it starts spawning `ConnectionResetError`s. -- ___ Python tracker <https://bugs.python.org/issue39010> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue39010] ProactorEventLoop raises unhandled ConnectionResetError
Jonathan Slenders added the comment: Thanks Victor for the reply. It looks like it's the self-socket in the BaseProactorEventLoop that gets closed. It's exactly this FD for which the exception is raised. We don't close the event loop anywhere. I also don't see `_close_self_pipe` being called anywhere. Debug logs don't provide any help. I'm looking into a reproducer. -- ___ Python tracker <https://bugs.python.org/issue39010> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue39010] ProactorEventLoop raises unhandled ConnectionResetError
Jonathan Slenders added the comment: Suppressing `ConnectionResetError` in `BaseProactorEventLoop._loop_self_reading`, like we do with `CancelledError` seems to fix it. Although I'm not sure what it causing the error, and whether we need to handle it somehow. -- ___ Python tracker <https://bugs.python.org/issue39010> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue39010] ProactorEventLoop raises unhandled ConnectionResetError
New submission from Jonathan Slenders : We have a snippet of code that runs perfectly fine using the `SelectorEventLoop`, but crashes *sometimes* using the `ProactorEventLoop`. The traceback is the following. The exception cannot be caught within the asyncio application itself (e.g., it is not attached to any Future or propagated in a coroutine). It probably propagates in `run_until_complete()`. File "C:\Python38\lib\asyncio\proactor_events.py", line 768, in _loop_self_reading f.result() # may raise File "C:\Python38\lib\asyncio\windows_events.py", line 808, in _poll value = callback(transferred, key, ov) File "C:\Python38\lib\asyncio\windows_events.py", line 457, in finish_recv raise ConnectionResetError(*exc.args) I can see that in `IocpProactor._poll`, `OSError` is caught and attached to the future, but not `ConnectionResetError`. I would expect that `ConnectionResetError` too will be attached to the future. In order to reproduce, run the following snippet on Python 3.8: from prompt_toolkit import prompt # pip install prompt_toolkit while 1: prompt('>') Hold down the enter key, and it'll trigger quickly. See also: https://github.com/prompt-toolkit/python-prompt-toolkit/issues/1023 -- components: asyncio messages: 358140 nosy: Jonathan Slenders, asvetlov, yselivanov priority: normal severity: normal status: open title: ProactorEventLoop raises unhandled ConnectionResetError versions: Python 3.8 ___ Python tracker <https://bugs.python.org/issue39010> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue24536] os.pipe() should return a structsequence (or namedtuple.)
New submission from Jonathan Slenders: As discussed on python-ideas, os.pipe should return a structsequence instead of a plain tuple. To be decided is the naming for the read and write end. Personally, I'm in favour of using readfd/writefd. our_pipe = pipe() os.write(our_pipe.writefd, b'data') os.read(our_pipe.readfd, 1024) -- components: IO messages: 245980 nosy: jonathan.slenders priority: normal severity: normal status: open title: os.pipe() should return a structsequence (or namedtuple.) versions: Python 3.6 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue24536 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue24536] os.pipe() should return a structsequence (or namedtuple.)
Jonathan Slenders added the comment: Niki Spahiev made a valid argument saying that the following code is common: if not hasattr(src, 'read'): src = open(src) This will break if we name it 'read'/'write' like the methods of a file object. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue24536 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Why is array.array('u') deprecated?
Why is array.array('u') deprecated? Will we get an alternative for a character array or mutable unicode string? Thanks! Jonathan -- https://mail.python.org/mailman/listinfo/python-list
Re: Why is array.array('u') deprecated?
Le vendredi 8 mai 2015 12:29:15 UTC+2, Steven D'Aprano a écrit : On Fri, 8 May 2015 07:14 pm, jonathan.slenders wrote: Why is array.array('u') deprecated? Will we get an alternative for a character array or mutable unicode string? Good question. Of the three main encodings for Unicode, two are variable-width: * UTF-8 uses 1-4 bytes per character * UTF-16 uses 2 or 4 bytes per character while UTF-32 is fixed-width (4 bytes per character). So you could try faking it with a 32-bit array and filling it with string.encode('utf-32'). I guess that doesn't work. I need to have something that I can pass to the re module for searching through it. Creating new strings all the time is no option. (Think about gigabyte strings.) -- https://mail.python.org/mailman/listinfo/python-list
Re: Why is array.array('u') deprecated?
Le vendredi 8 mai 2015 15:11:56 UTC+2, Peter Otten a écrit : So, this works perfectly fine and fast. But it scares me that it's deprecated and Python 4 will not support it anymore. Hm, this doesn't even work with Python 3: My mistake. I should have tested better. data = array.array(u, ux*1000) data[100] = y re.search(y, data) Traceback (most recent call last): File stdin, line 1, in module File /usr/lib/python3.4/re.py, line 166, in search return _compile(pattern, flags).search(string) TypeError: can't use a string pattern on a bytes-like object You can search for bytes re.search(by, data) _sre.SRE_Match object; span=(400, 401), match=b'y' data[101] = z re.search(by, data) _sre.SRE_Match object; span=(400, 401), match=b'y' re.search(byz, data) re.search(by\0\0\0z, data) _sre.SRE_Match object; span=(400, 405), match=b'y\x00\x00\x00z' but if that is good enough you can use a bytearray in the first place. Maybe I'll try that. Thanks for the suggestions! Jonathan -- https://mail.python.org/mailman/listinfo/python-list
Re: Why is array.array('u') deprecated?
Can you expand a bit on how array(u) helps here? Are the matches in the gigabyte range? I have a string of unicode characters, e.g.: data = array.array('u', u'x' * 10) Then I need to change some data in the middle of this string, for instance: data[50] = 'y' Then I want to use re to search in this text: re.search('y', data) This has to be fast. I really don't want to split and concatenate strings. Re should be able to process it and the expressions can be much more complex than this. (I think it should be anything that implements the buffer protocol). So, this works perfectly fine and fast. But it scares me that it's deprecated and Python 4 will not support it anymore. -- https://mail.python.org/mailman/listinfo/python-list
Re: How do I check if a string is a prefix of any possible other string that matches a given regex.
Le mercredi 8 octobre 2014 01:40:11 UTC+2, MRAB a écrit : If you're not interested in generating an actual regex, but only in matching the prefix, then it sounds like you want partial matching. The regex module supports that: https://pypi.python.org/pypi/regex Wow, thanks a lot! That really helps me. -- https://mail.python.org/mailman/listinfo/python-list
How do I check if a string is a prefix of any possible other string that matches a given regex.
Hi everyone, Probably I'm turning the use of regular expressions upside down with this question. I don't want to write a regex that matches prefixes of other strings, I know how to do that. I want to generate a regex -- given another regex --, that matches all possible strings that are a prefix of a string that matches the given regex. E.g. You have the regex ^[a-z]*4R$ then the strings a, ab, A4 ab4 are prefixes of this regex (because there is a way of adding characters that causes the regex to match), but 4a or a44 or not. How do I programmatically create a regex that matches a, ab, A4, etc.. but not 4a, a44, etc.. Logically, I'd think it should be possible by running the input string against the state machine that the given regex describes, and if at some point all the input characters are consumed, it's a match. (We don't have to run the regex until the end.) But I cannot find any library that does it... Thanks a lot, if anyone knows the answer to this question! Cheers, Jonathan -- https://mail.python.org/mailman/listinfo/python-list
Re: How do I check if a string is a prefix of any possible other string that matches a given regex.
Logically, I'd think it should be possible by running the input string against the state machine that the given regex describes, and if at some point all the input characters are consumed, it's a match. (We don't have to run the regex until the end.) But I cannot find any library that does it... Strictly speaking, a DFA or NFA always consumes the entire input; the question of interest is whether it halts in an accepting state or not. It would be easy to transform a DFA or NFA in the manner that you want, though. For each non-accepting state, determine whether it has any transitions that lead in one or more steps to an accepting state. Modify the FSM so that each such state is also an accepting state. Thanks, I'll make every state of the FSM an accepting state. My use case is to implement autocompletion for a regular language. So I think if the input is accepted by the FSM that I build, it's a valid prefix, and the autocompletion can be generated by looking at which transitions are possible at that point. More pointers are welcome, but I think that I have enough to start the implementation. -- https://mail.python.org/mailman/listinfo/python-list
Re: Looking for a name for a deployment framework...
Le mardi 25 juin 2013 06:38:44 UTC+2, Chris Rebert a écrit : Er, Salt is likewise written in Python. You're right. Salt is also Python, excuse me, and it's very powerful as well. -- http://mail.python.org/mailman/listinfo/python-list
Looking for a name for a deployment framework...
Hi all, Any suggestions for a good name, for a framework that does automatic server deployments? It's like Fabric, but more powerful. It has some similarities with Puppet, Chef and Saltstack, but is written in Python. Key points are that it uses Python, but is still very declarative and supports introspection. It supports parallel deployments, and interactivity. And it has a nice commandline shell with autocompletion for traversing the deployment tree. The repository: https://github.com/jonathanslenders/python-deployer/tree/refactoring-a-lot-v2 Suggestions welcome :) Jonathan -- http://mail.python.org/mailman/listinfo/python-list
Re: Looking for a name for a deployment framework...
Thanks everyone, I'll think about it. The main reason is that I'm working on the documentation, and this a a good opportunity to think about the naming. python-deploy-framework or python-deployer could be too boring. -- http://mail.python.org/mailman/listinfo/python-list