[issue44115] Improve conversions for fractions

2021-05-12 Thread Martin Teichmann
Change by Martin Teichmann : -- keywords: +patch pull_requests: +24705 stage: -> patch review pull_request: https://github.com/python/cpython/pull/26064 ___ Python tracker <https://bugs.python.org/issu

[issue44115] Improve conversions for fractions

2021-05-12 Thread Martin Teichmann
New submission from Martin Teichmann : Currently, fraction.Fractions can be generated from floats via their as_integer_ratio method. This had been extended to also work with the Decimals class. It would be more generic - and IMHO more Pythonic - to just allow any data type, as long as it has

[issue37334] Add a cancel method to asyncio Queues

2021-05-12 Thread Martin Teichmann
Martin Teichmann added the comment: This is a years old issue, unfortunately it never got neither merged nor rejected. I just rebased it and hope somebody could finish the review. -- versions: +Python 3.11 -Python 3.8 ___ Python tracker <ht

[issue37334] Add a cancel method to asyncio Queues

2019-11-23 Thread Martin Teichmann
Martin Teichmann added the comment: I do not think that exposing the lists of futures does any good. I cannot come up with a semantics that could be implemented with that other than the one proposed. Also I think that close() or cancel() is something a reader intuitively understands, while

[issue37334] Add a cancel method to asyncio Queues

2019-11-22 Thread Martin Teichmann
Martin Teichmann added the comment: Yes, in the one-producer-many-consumers situation on can indeed to the trick with the None. But this is just a clumsy hack, cancelling the tasks is IMHO more in line with asyncio. In the many-producers-one-consumer scenario this does not work. The one

[issue37334] Add a cancel method to asyncio Queues

2019-11-22 Thread Martin Teichmann
Martin Teichmann added the comment: Hi Andrew, I still don't get your point. First, this is an extension to the asyncio library, so concurrency is not an issue. And sure, if you call random methods of an object without any reason the outcome won't be anything useful, why, in your example

[issue37334] Add a cancel method to asyncio Queues

2019-06-24 Thread Martin Teichmann
Martin Teichmann added the comment: Given the reactions I gather "close" is a better name for the method, so I changed it accordingly. In the current implementation, items that had been put on the queue but not processed yet still get processed after the close, a

[issue37334] Add a cancel method to asyncio Queues

2019-06-20 Thread Martin Teichmann
Martin Teichmann added the comment: I also thought about `.close()` but then found `.cancel()` more intuitive. But intuition is not universal, so I am open to any wording. -- ___ Python tracker <https://bugs.python.org/issue37

[issue37334] Add a cancel method to asyncio Queues

2019-06-19 Thread Martin Teichmann
Change by Martin Teichmann : -- keywords: +patch pull_requests: +14061 stage: -> patch review pull_request: https://github.com/python/cpython/pull/14227 ___ Python tracker <https://bugs.python.org/issu

[issue37334] Add a cancel method to asyncio Queues

2019-06-19 Thread Martin Teichmann
New submission from Martin Teichmann : When working with queues, it is not uncommon that at some point the producer stops producing data for good, or the consumer stops consuming, for example because a network connection broke down or some user simply closed the session. In this situation

[issue33413] asyncio.gather should not use special Future

2018-05-10 Thread Martin Teichmann
Martin Teichmann <martin.teichm...@gmail.com> added the comment: I looked a bit into the details, and found that bpo-30048 created the described weird behavior. There they fixed the problem that a cancel is ignored if a coroutine manages to cancel its own task and return immediately. As

[issue33413] asyncio.gather should not use special Future

2018-05-02 Thread Martin Teichmann
Change by Martin Teichmann <martin.teichm...@gmail.com>: -- keywords: +patch pull_requests: +6388 stage: -> patch review ___ Python tracker <rep...@bugs.python.org> <https://bugs.pyt

[issue33413] asyncio.gather should not use special Future

2018-05-02 Thread Martin Teichmann
New submission from Martin Teichmann <martin.teichm...@gmail.com>: asyncio.gather() returns a _GatheringFuture, which inherits from asyncio.Future. This is weird in current asyncio, as futures are supposed to be created with loop.create_future(). So I tried to reimplement gather() w

[issue30306] release arguments of contextmanager

2017-05-17 Thread Martin Teichmann
Martin Teichmann added the comment: Hi, so where do we go from here? I could write the proposed allow_recreation flag, but IMHO this adds only dead code, as it is of no need at all. I don't think code gets more clear by adding dead code... I opted for one line more of comment, I think

[issue30306] release arguments of contextmanager

2017-05-10 Thread Martin Teichmann
Martin Teichmann added the comment: I personally prefer the current situation. The problem is the following: when an @contextmanager is first called, we don't know yet whether the user wants to use it directly, or as a decorator, so we have to have some kind of hybrid class. Once it's used

[issue30306] release arguments of contextmanager

2017-05-08 Thread Martin Teichmann
Changes by Martin Teichmann <martin.teichm...@gmail.com>: -- pull_requests: +1602 ___ Python tracker <rep...@bugs.python.org> <http://bugs.python

[issue30306] release arguments of contextmanager

2017-05-08 Thread Martin Teichmann
New submission from Martin Teichmann: The arguments of a function which was decorated to be a context manager are stored inside the context manager, and are thus kept alive. This is a memory leak. Example: @contextmanager def f(a): do_something_with(a) a = None

[issue29432] wait_for(gather(...)) logs weird error message

2017-02-08 Thread Martin Teichmann
Martin Teichmann added the comment: I added a solution to this problem. I just silence the bad error message by overwriting _GatheringFuture.__del__ to do nothing. This may have undesired side effects, though. -- ___ Python tracker <

[issue29432] wait_for(gather(...)) logs weird error message

2017-02-03 Thread Martin Teichmann
New submission from Martin Teichmann: when waiting for a gather that times out, everything works as expected, yet a weird error message is logged. To give a minimal example: import asyncio @asyncio.coroutine def main(): try: sleep = asyncio.sleep(0.2

[issue29432] wait_for(gather(...)) logs weird error message

2017-02-03 Thread Martin Teichmann
Changes by Martin Teichmann <martin.teichm...@gmail.com>: -- type: -> behavior ___ Python tracker <rep...@bugs.python.org> <http://bugs.pyt

[issue28797] Modifying class __dict__ inside __set_name__

2016-11-28 Thread Martin Teichmann
Martin Teichmann added the comment: I personally prefer the first patch, which iterates over a copy of __dict__. Making a copy of a dict is actually a pretty fast operation, I would even expect that it is faster than the proposed alternative, creating tuples. Even if the second approach

[issue23722] During metaclass.__init__, super() of the constructed class does not work

2016-09-10 Thread Martin Teichmann
Martin Teichmann added the comment: This is the originial patch rebased such that it applies to the current master. As a detail in the discussion: "__classcell__" is not visible during the execution of the class body, as it is added at the end of the class body. In t

[issue27366] PEP487: Simpler customization of class creation

2016-07-25 Thread Martin Teichmann
Martin Teichmann added the comment: I looked over the patch once more and found some places where I didn't follow normal coding standards. I changed that, namely now the code returns -1 meaning an exception happened and 0 on success, which is what many functions in typeobject.c do. So I think

[issue27366] PEP487: Simpler customization of class creation

2016-07-24 Thread Martin Teichmann
Martin Teichmann added the comment: Thanks for the nice review! I made the proposed changes, see attached patch. I am still waiting for a decision whether type.__setattr__ should call __set_name__ from python-dev, once that's sorted out I'll implement and test the one or the other behavior

[issue27366] PEP487: Simpler customization of class creation

2016-07-22 Thread Martin Teichmann
Changes by Martin Teichmann <martin.teichm...@gmail.com>: Added file: http://bugs.python.org/file43835/pep487.patch ___ Python tracker <rep...@bugs.python.org> <http://bugs.python

[issue27366] PEP487: Simpler customization of class creation

2016-07-22 Thread Martin Teichmann
Changes by Martin Teichmann <martin.teichm...@gmail.com>: Removed file: http://bugs.python.org/file43834/pep487.patch ___ Python tracker <rep...@bugs.python.org> <http://bugs.python

[issue27366] PEP487: Simpler customization of class creation

2016-07-22 Thread Martin Teichmann
Changes by Martin Teichmann <martin.teichm...@gmail.com>: Added file: http://bugs.python.org/file43834/pep487.patch ___ Python tracker <rep...@bugs.python.org> <http://bugs.python

[issue27366] PEP487: Simpler customization of class creation

2016-07-22 Thread Martin Teichmann
Changes by Martin Teichmann <martin.teichm...@gmail.com>: Removed file: http://bugs.python.org/file43611/pep487a.patch ___ Python tracker <rep...@bugs.python.org> <http://bugs.python

[issue23722] During metaclass.__init__, super() of the constructed class does not work

2016-07-17 Thread Martin Teichmann
Changes by Martin Teichmann <martin.teichm...@gmail.com>: Added file: http://bugs.python.org/file43766/pep487.patch ___ Python tracker <rep...@bugs.python.org> <http://bugs.python

[issue23722] During metaclass.__init__, super() of the constructed class does not work

2016-07-17 Thread Martin Teichmann
Changes by Martin Teichmann <martin.teichm...@gmail.com>: Removed file: http://bugs.python.org/file43765/pep487.patch ___ Python tracker <rep...@bugs.python.org> <http://bugs.python

[issue23722] During metaclass.__init__, super() of the constructed class does not work

2016-07-17 Thread Martin Teichmann
Changes by Martin Teichmann <martin.teichm...@gmail.com>: Removed file: http://bugs.python.org/file38604/patch ___ Python tracker <rep...@bugs.python.org> <http://bugs.python

[issue23722] During metaclass.__init__, super() of the constructed class does not work

2016-07-17 Thread Martin Teichmann
Martin Teichmann added the comment: Currently, a class is created as follows: the compiler turns the class statement into a call to __build_class__. This runs the class body. If __class__ or super() is used within a method of the class, an empty PyCell is created, to be filled later

[issue27366] PEP487: Simpler customization of class creation

2016-07-13 Thread Martin Teichmann
Changes by Martin Teichmann <martin.teichm...@gmail.com>: Removed file: http://bugs.python.org/file43506/pep487.patch ___ Python tracker <rep...@bugs.python.org> <http://bugs.python

[issue27366] PEP487: Simpler customization of class creation

2016-07-02 Thread Martin Teichmann
Martin Teichmann added the comment: This is a C implementation of PEP 487, directly in the Python core -- Added file: http://bugs.python.org/file43611/pep487a.patch ___ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/i

[issue27366] PEP487: Simpler customization of class creation

2016-06-22 Thread Martin Teichmann
New submission from Martin Teichmann: This is the implementation of PEP 487. It adds a metaclass to types that calls a method on a class once it is subclassed. This way one can customize the creation of classes without the need to write an own metaclass. As a second functionality, it calls

[issue24431] StreamWriter.drain is not callable concurrently

2015-06-11 Thread Martin Teichmann
New submission from Martin Teichmann: Currently there is an assert statement asserting that no two tasks (asyncio tasks, that is) can use StreamWriter.drain at the same time. This is a weird limitiation, if there are two tasks writing to the same network socket, there is no reason why not both

[issue23722] During metaclass.__init__, super() of the constructed class does not work

2015-03-23 Thread Martin Teichmann
Martin Teichmann added the comment: A note on the implementation: The compiler leaves a __cell__ entry in the class' namespace, which is then filled by type.__new__, and removed from the namespace by the latter. This is the same way it is done for __qualname__. As the patch tampers

[issue23722] During metaclass.__init__, super() of the constructed class does not work

2015-03-20 Thread Martin Teichmann
New submission from Martin Teichmann: When a new class is initialized with __init__ in a metaclass, the __class__ cell of the class about to be initialized is not set yet, meaning that super() does not work. This is a known but fixable problem. The attached patch moves the initialization

[issue22412] Towards an asyncio-enabled command line

2014-09-16 Thread Martin Teichmann
Martin Teichmann added the comment: well, I beg to differ. Again, to your points: to a) You claim that my flag would have to be supported by every python platform. Well, the very same built-in function has another flag, PyCF_ONLY_AST, whose precise meaning, according to the docs, might change

[issue22412] Towards an asyncio-enabled command line

2014-09-16 Thread Martin Teichmann
Martin Teichmann added the comment: Well, so I am giving up, apparenty my work is not wanted here. But not before submitting at least the last version of my patch. I seperated out my _input function into two, start_input and continue_input, which are supposed to work in a loop

[issue22412] Towards an asyncio-enabled command line

2014-09-16 Thread Martin Teichmann
Martin Teichmann added the comment: And as a last comment, just for completeness, a complete async console. With it you can do cool things like from asyncio import sleep, async def f(): ...yield from sleep(3) ...print(done) yield from f() [after 3 seconds] done async(f()) [wait

[issue22412] Towards an asyncio-enabled command line

2014-09-15 Thread Martin Teichmann
Martin Teichmann added the comment: Hi Guido, thanks for the quick response, so my response to your post: to 1: thanks! to 2: I am trying to put most of the stuff into a 3rd party module, unfortunately I need changes in the python compiler, and given that monkey patching is not so simple

[issue22412] Towards an asyncio-enabled command line

2014-09-15 Thread Martin Teichmann
Martin Teichmann added the comment: As promised, a new patch now for the current head. Last time I apparently got confused with how hg works, sorry. -- Added file: http://bugs.python.org/file36623/patch2 ___ Python tracker rep...@bugs.python.org http

[issue22412] Towards an asyncio-enabled command line

2014-09-14 Thread Martin Teichmann
New submission from Martin Teichmann: This patch is supposed to facilitate using the asyncio package on the command line. It contains two things: First, a coroutine version of builtin.input, so that it can be called while a asyncio event loop is running. Secondly, it adds a new flag

[issue20518] multiple inheritance + C extension = possibly unexpected __base__

2014-02-08 Thread Martin Teichmann
Martin Teichmann added the comment: I've been working a bit on a solution to this issue, one proposal is in the attached patch. The patch adds a new flag to tp_flags, called Py_TPFLAGS_SOLID, which marks a class as being solid, i.e. its memory layout is incompatible with its parent layout. C

[issue20518] Weird behavior with multiple inheritance when C classes involved

2014-02-05 Thread Martin Teichmann
New submission from Martin Teichmann: Python behaves odd with regards to multiple inheritance and classes written in C. I stumbled over this problem while working with PyQt4, but soon realized that part of the problem is not actually in that library, but is deep down in the CPython core