Re: Error handling in context managers
Gregory Ewing wrote: > Israel Brewster wrote: >> The problem is that, from time to time, I can't get a connection, the >> result being that cursor is None, > > That's your problem right there -- you want a better-behaved > version of psql_cursor(). > > def get_psql_cursor(): > c = psql_cursor() > if c is None: >raise CantGetAConnectionError() > return c > > with get_psql_cursor() as c: > ... You still need to catch the error -- which leads to option (3) in my zoo, the only one that is actually usable. If one contextmanager cannot achieve what you want, use two: $ cat conditional_context_raise.py import sys from contextlib import contextmanager class NoConnection(Exception): pass class Cursor: def execute(self, sql): print("EXECUTING", sql) @contextmanager def cursor(): if "--fail" in sys.argv: raise NoConnection yield Cursor() @contextmanager def no_connection(): try: yield except NoConnection: print("no connection") with no_connection(), cursor() as cs: cs.execute("insert into...") $ python3 conditional_context_raise.py EXECUTING insert into... $ python3 conditional_context_raise.py --fail no connection If you want to ignore the no-connection case use contextlib.suppress(NoConnection) instead of the custom no_connection() manager. -- https://mail.python.org/mailman/listinfo/python-list
[RELEASED] Python 3.4.6 and Python 3.5.3 are now available
On behalf of the Python development community and the Python 3.4 and Python 3.5 release teams, I'm delighted to announce the availability of Python 3.4.6 and Python 3.5.3. Python 3.4 is now in "security fixes only" mode. This is the final stage of support for Python 3.4. Python 3.4 now only receives security fixes, not bug fixes, and Python 3.4 releases are source code only--no more official binary installers will be produced. Python 3.5 is still in active "bug fix" mode. Python 3.5.3 contains many incremental improvements over Python 3.5.2. There were literally no code changes between rc1 and final for either release. The only change--apart from the necessary updates from "rc1" to final--was a single copyright notice update for one of the OS X ".plist" property list files in 3.5.3 final. You can find Python 3.5.3 here: https://www.python.org/downloads/release/python-353/ And you can find Python 3.4.6 here: https://www.python.org/downloads/release/python-346/ Best wishes, //arry/ -- https://mail.python.org/mailman/listinfo/python-list
Re: Emulating Final classes in Python
Op 17-01-17 om 08:05 schreef Steven D'Aprano: > I wish to emulate a "final" class using Python, similar to bool: > > py> class MyBool(bool): > ... pass > ... > Traceback (most recent call last): > File "", line 1, in > TypeError: type 'bool' is not an acceptable base type > > > It doesn't have to be absolutely bulletproof, but anyone wanting to subclass > my > class should need to work for it, which hopefully will tell them that they're > doing something unsupported. > > Any hints? I find those kind of classes annoying as hell and nobody has ever given me a good reason for them. What good was it to change Lock from a factory function to a class if you can't subclass the result anyway. The result will probably be that users that would prefer to subclass your class will monkey-patch it. Something like: class MyLock: def __init__(self): self.lock = Lock() def __getattr__(self, attr): return getattr(self.lock, attr) So I wonder what reasons do you have prefering that your users monkey-patch your class instead of subclassing it? -- Antoon Pardon -- https://mail.python.org/mailman/listinfo/python-list
Re: Emulating Final classes in Python
Hi Steven, On 17/01/17 07:05, Steven D'Aprano wrote: I wish to emulate a "final" class using Python, similar to bool: [snip] It doesn't have to be absolutely bulletproof, but anyone wanting to subclass my class should need to work for it, which hopefully will tell them that they're doing something unsupported. When someone brings up something like this you usually quote the "consenting adults" argument, so I'll throw it back at you - why not just add it to your documentation? E. -- https://mail.python.org/mailman/listinfo/python-list
Re: tokenize.untokenize adding line continuation characters
On Tuesday, January 17, 2017 at 2:47:03 AM UTC, Steven D'Aprano wrote: > On Tuesday 17 January 2017 09:42, Rotwang wrote: > > > Here's something odd I've found with the tokenize module: > [...] > > Copypasted from iPython: > > It's not impossible that iPython is doing something funny with the tokenize > module. It happens outside iPython: Python 3.4.3 (default, Oct 14 2015, 20:28:29) [GCC 4.8.4] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import io, tokenize >>> tokenize.untokenize(tokenize.tokenize(io.BytesIO('if x:\n >>> y'.encode()).readline)).decode() 'if x:\ny\\\n' and also in Python 2: Python 2.7.6 (default, Mar 22 2014, 22:59:56) [GCC 4.8.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import io, tokenize >>> tokenize.untokenize(tokenize.generate_tokens(io.BytesIO('if x:\n >>> y').readline)) 'if x:\ny\\\n' > Before reporting it as a bug, I recommend that you confirm that it also > occurs in the standard Python interpreter and isn't iPython specific. Is this behaviour actually a bug, as opposed to a feature I don't understand? -- https://mail.python.org/mailman/listinfo/python-list
Re: tokenize.untokenize adding line continuation characters
Rotwang wrote: > Here's something odd I've found with the tokenize module: tokenizing 'if > x:\ny' and then untokenizing the result adds '\\\n' to the end. > Attempting to tokenize the result again fails because of the backslash > continuation with nothing other than a newline after it. On the other > hand, if the original string ends with a newline then it works fine. Can > anyone explain why this happens? > I'm using Python 3.4.3 on Windows 8. Copypasted from iPython: This looks like a bug... $ python3.4 -c 'import tokenize as t, io; print(t.untokenize(t.tokenize(io.BytesIO(b"if x:\n y").readline)))' b'if x:\n y\\\n' ...that is fixed now: $ python3.6 -c 'import tokenize as t, io; print(t.untokenize(t.tokenize(io.BytesIO(b"if x:\n y").readline)))' b'if x:\n y' A quick search brought up multiple bug reports, among them http://bugs.python.org/issue12691 -- https://mail.python.org/mailman/listinfo/python-list
Re: tokenize.untokenize adding line continuation characters
On Tuesday, January 17, 2017 at 11:11:27 AM UTC, Peter Otten wrote: > Rotwang wrote: > > > Here's something odd I've found with the tokenize module: tokenizing 'if > > x:\ny' and then untokenizing the result adds '\\\n' to the end. > > Attempting to tokenize the result again fails because of the backslash > > continuation with nothing other than a newline after it. On the other > > hand, if the original string ends with a newline then it works fine. Can > > anyone explain why this happens? > > > I'm using Python 3.4.3 on Windows 8. Copypasted from iPython: > > This looks like a bug... > > $ python3.4 -c 'import tokenize as t, io; > print(t.untokenize(t.tokenize(io.BytesIO(b"if x:\n y").readline)))' > b'if x:\n y\\\n' > > ...that is fixed now: > > $ python3.6 -c 'import tokenize as t, io; > print(t.untokenize(t.tokenize(io.BytesIO(b"if x:\n y").readline)))' > b'if x:\n y' > > A quick search brought up multiple bug reports, among them > > http://bugs.python.org/issue12691 Ah, thanks. I did search for bug reports before I started this thread but didn't find anything. -- https://mail.python.org/mailman/listinfo/python-list
Python, asyncio, and systemd
If I write a web server using asyncio (and the aiohttp package), I can spin up the server with: await loop.create_server(app.make_handler(), "0.0.0.0", 8080) This works fine for a high port, but if I want to bind to port 80, I need to either start as root and then drop privileges, or get given the socket by someone else. With systemd, the latter is an option; you configure a service unit and a socket unit, and when the service gets started, it's given a bound listening socket as FD 3. Most of the work is pretty straight-forward, but I ran into one problem. The event loop's create_server() method calls a private _start_serving method, which means I can't (or rather, I shouldn't) just replicate create_server. This works, but it's naughty: sock = socket.socket(fileno=3) sock.setblocking(False) loop._start_serving(app.make_handler(), sock) What's the official way to say to asyncio "here's a listening socket, start managing it for me"? ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Python, asyncio, and systemd
On Tue, Jan 17, 2017 at 9:57 AM, Chris Angelico wrote: > If I write a web server using asyncio (and the aiohttp package), I can > spin up the server with: > > await loop.create_server(app.make_handler(), "0.0.0.0", 8080) > > This works fine for a high port, but if I want to bind to port 80, I > need to either start as root and then drop privileges, or get given > the socket by someone else. With systemd, the latter is an option; you > configure a service unit and a socket unit, and when the service gets > started, it's given a bound listening socket as FD 3. > > Most of the work is pretty straight-forward, but I ran into one > problem. The event loop's create_server() method calls a private > _start_serving method, which means I can't (or rather, I shouldn't) > just replicate create_server. This works, but it's naughty: > > sock = socket.socket(fileno=3) > > sock.setblocking(False) > loop._start_serving(app.make_handler(), sock) > > What's the official way to say to asyncio "here's a listening socket, > start managing it for me"? I haven't tried this but create_server takes a "sock" keyword-argument. https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.AbstractEventLoop.create_server -- https://mail.python.org/mailman/listinfo/python-list
Re: Python, asyncio, and systemd
On 2017-01-17 17:57, Chris Angelico wrote: > If I write a web server using asyncio (and the aiohttp package), I can > spin up the server with: > > await loop.create_server(app.make_handler(), "0.0.0.0", 8080) > > This works fine for a high port, but if I want to bind to port 80, I > need to either start as root and then drop privileges, or get given > the socket by someone else. With systemd, the latter is an option; you > configure a service unit and a socket unit, and when the service gets > started, it's given a bound listening socket as FD 3. > > Most of the work is pretty straight-forward, but I ran into one > problem. The event loop's create_server() method calls a private > _start_serving method, which means I can't (or rather, I shouldn't) > just replicate create_server. This works, but it's naughty: > > sock = socket.socket(fileno=3) > > sock.setblocking(False) > loop._start_serving(app.make_handler(), sock) > > What's the official way to say to asyncio "here's a listening socket, > start managing it for me"? Hi Chris, you might be interested in ticket [1], my module socketfromfd [2] and some code I wrote for a HTTP server with socket activation [3]. The latter does not use asyncio but shows how to use socket activation with systemd. The blog posting [4] has some example code in case you don't want to use systemd's Python module. [1] https://bugs.python.org/issue28134 [2] https://github.com/tiran/socketfromfd [3] https://github.com/latchset/custodia/blob/master/custodia/httpd/server.py#L491 [4] http://0pointer.de/blog/projects/socket-activation.html Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Python, asyncio, and systemd
On Wed, Jan 18, 2017 at 4:06 AM, Ian Kelly wrote: >> What's the official way to say to asyncio "here's a listening socket, >> start managing it for me"? > > I haven't tried this but create_server takes a "sock" keyword-argument. > > https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.AbstractEventLoop.create_server Oh. Wow. I am blind, or an idiot. That is exactly what I'm looking for. My code now looks like this: if sock: srv = await loop.create_server(app.make_handler(), sock=sock) else: srv = await loop.create_server(app.make_handler(), "0.0.0.0", port) sock = srv.sockets[0] print("Listening on %s:%s" % sock.getsockname(), file=sys.stderr) According to the docs, host and port must be unset (None) if sock is given. It'd be nice if they could simply be ignored, in which case I could just pass in all three parameters. (Yes, I'm forcing this to IPv4 for this app, rather than using None or "::" to accept IPv6 as well. If you're copying this code into your app, you should probably accept IPv6, unless you know otherwise.) But wow, I just completely didn't see that. I am incredible. Thank you Ian! ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Python 3.6 Installation
I having problems installing Python 3.6. I was using Python 2.7 successfully. Today, I installed python-3.6.0.exe. At the end of the installation I got a message saying the installation was successful. When attempt to start Python, I get the following Application Error: The application was unable to start correctly (0xc07b). Click OK to close the application. I am using Windows 7 Professional, 64 bit. Can you help? Thanks Earl Izydore 412-968- ext. 14663 eizyd...@zoll.com [http://www.zoll.com/uploadedImages/images/emailsignaturelogo9_09.jpg] An Asahi Kasei Group Company -- https://mail.python.org/mailman/listinfo/python-list
Re: Error handling in context managers
On Jan 16, 2017, at 1:27 PM, Terry Reedy wrote: > > On 1/16/2017 1:06 PM, Israel Brewster wrote: >> I generally use context managers for my SQL database connections, so I can >> just write code like: >> >> with psql_cursor() as cursor: >> >> >> And the context manager takes care of making a connection (or getting a >> connection from a pool, more likely), and cleaning up after the fact (such >> as putting the connection back in the pool), even if something goes wrong. >> Simple, elegant, and works well. >> >> The problem is that, from time to time, I can't get a connection, the result >> being that cursor is None, > > This would be like open('bad file') returning None instead of raising > FileNotFoundError. > >> and attempting to use it results in an AttributeError. > > Just as None.read would. > > Actually, I have to wonder about your claim. The with statement would look > for cursor.__enter__ and then cursor.__exit__, and None does not have those > methods. In other words, the expression following 'with' must evaluate to a > context manager and None is not a context manager. > > >>> with None: pass > > Traceback (most recent call last): > File "", line 1, in >with None: pass > AttributeError: __enter__ > > Is psql_cursor() returning a fake None object with __enter__ and __exit__ > methods? No, the *context manager*, which I call in the with *does* have __enter__ and __exit__ methods. It's just that the __enter__ method returns None when it can't get a connection. So the expression following with *does* evaluate to a context manager, but the expression following as evaluates to None. --- Israel Brewster Systems Analyst II Ravn Alaska 5245 Airport Industrial Rd Fairbanks, AK 99709 (907) 450-7293 --- > > -- > Terry Jan Reedy > > -- > https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: Error handling in context managers
On Jan 16, 2017, at 8:01 PM, Gregory Ewing wrote: > > Israel Brewster wrote: >> The problem is that, from time to time, I can't get a connection, the result >> being that cursor is None, > > That's your problem right there -- you want a better-behaved > version of psql_cursor(). > > def get_psql_cursor(): > c = psql_cursor() > if c is None: > raise CantGetAConnectionError() > return c > > with get_psql_cursor() as c: > ... > Ok, fair enough. So I get a better exception, raised at the proper time. This is, in fact, better - but doesn't actually change how I would *handle* the exception :-) --- Israel Brewster Systems Analyst II Ravn Alaska 5245 Airport Industrial Rd Fairbanks, AK 99709 (907) 450-7293 --- > -- > Greg > -- > https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: Error handling in context managers
On Jan 16, 2017, at 11:34 PM, Peter Otten <__pete...@web.de> wrote: > > Gregory Ewing wrote: > >> Israel Brewster wrote: >>> The problem is that, from time to time, I can't get a connection, the >>> result being that cursor is None, >> >> That's your problem right there -- you want a better-behaved >> version of psql_cursor(). >> >> def get_psql_cursor(): >>c = psql_cursor() >>if c is None: >> raise CantGetAConnectionError() >>return c >> >> with get_psql_cursor() as c: >>... > > You still need to catch the error -- which leads to option (3) in my zoo, > the only one that is actually usable. If one contextmanager cannot achieve > what you want, use two: > > $ cat conditional_context_raise.py > import sys > from contextlib import contextmanager > > class NoConnection(Exception): >pass > > class Cursor: >def execute(self, sql): >print("EXECUTING", sql) > > @contextmanager > def cursor(): >if "--fail" in sys.argv: >raise NoConnection >yield Cursor() > > @contextmanager > def no_connection(): >try: >yield >except NoConnection: >print("no connection") > > with no_connection(), cursor() as cs: >cs.execute("insert into...") > $ python3 conditional_context_raise.py > EXECUTING insert into... > $ python3 conditional_context_raise.py --fail > no connection > > If you want to ignore the no-connection case use > contextlib.suppress(NoConnection) instead of the custom no_connection() > manager. Fun :-) I'll have to play around with that. Thanks! :-) --- Israel Brewster Systems Analyst II Ravn Alaska 5245 Airport Industrial Rd Fairbanks, AK 99709 (907) 450-7293 --- > > -- > https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: Emulating Final classes in Python
On 01/16/2017 11:32 PM, Steven D'Aprano wrote: On Tuesday 17 January 2017 18:05, Steven D'Aprano wrote: I wish to emulate a "final" class using Python, similar to bool: I may have a solution: here's a singleton (so more like None than bools) where instantiating the class returns the singleton, and subclassing the class fails: class DoneMeta(type): _final = None def __new__(meta, name, bases, ns): if meta._final is None: meta._final = cls = super().__new__(meta, name, bases, ns) return cls elif meta._final in bases: # Not sure this check is needed. raise TypeError('base class is final and cannot be subclassed') This will make DoneMeta a one-shot, meaning you'll have to make more DoneMeta's if you need more than one unsubclassable class. class DoneType(metaclass=DoneMeta): __slots__ = () _instance = None def __new__(cls): if cls._instance is None: cls._instance = inst = super().__new__(cls) return inst return cls._instance def __repr__(self): return '' And this has to do with single instances, which is not what you asked about. Here's some sample code that creates a Final class; any class that subclasses from it cannot be further subclassed: -- 8< Final = None class FinalMeta(type): def __new__(metacls, cls, bases, clsdict): print('-' * 50) print('class: ', cls) print('bases: ', bases) if Final is not None: for base in bases: if base is not Final and issubclass(base, Final): print('should raise') print('-' * 50) return type.__new__(metacls, cls, bases, clsdict) class Final(metaclass=FinalMeta): pass class One(Final): pass class Two(One): pass class Three(Two): pass class Ten(Final): pass -- 8< Change the "should raise" to a raise, remove the other print()s, and away you go. Should work in any Python 3. -- ~Ethan~ -- https://mail.python.org/mailman/listinfo/python-list
Re: Python 3.6 Installation
On 1/17/2017 1:23 PM, Earl Izydore wrote: I having problems installing Python 3.6. I was using Python 2.7 successfully. Today, I installed python-3.6.0.exe. Which binary? from where? At the end of the installation I got a message saying the installation was successful. When attempt to start Python, I get the following Application Error: The application was unable to start correctly (0xc07b). Click OK to close the application. Searching the web for 0xc07b gets many hits and suggestions. For python, searching stackoverflow.con is probably better. https://stackoverflow.com/questions/20650596/cannot-open-python-error-0xc07b is only one of the hits. I am using Windows 7 Professional, 64 bit. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: Emulating Final classes in Python
On Tue, 17 Jan 2017 08:54 pm, Erik wrote: > Hi Steven, > > On 17/01/17 07:05, Steven D'Aprano wrote: >> I wish to emulate a "final" class using Python, similar to bool: > > [snip] > >> It doesn't have to be absolutely bulletproof, but anyone wanting to >> subclass my class should need to work for it, which hopefully will tell >> them that they're doing something unsupported. > > When someone brings up something like this you usually quote the > "consenting adults" argument, so I'll throw it back at you - why not > just add it to your documentation? A very good question :-) Why am I doing this? Part of the answer is simply because I can. I want to see how far I can go to lock down the class in pure Python code. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list
Re: Emulating Final classes in Python
On Wed, 18 Jan 2017 06:14 am, Ethan Furman wrote: > On 01/16/2017 11:32 PM, Steven D'Aprano wrote: >> On Tuesday 17 January 2017 18:05, Steven D'Aprano wrote: >> >>> I wish to emulate a "final" class using Python, similar to bool: >> >> I may have a solution: here's a singleton (so more like None than bools) >> where instantiating the class returns the singleton, and subclassing the >> class fails: >> >> class DoneMeta(type): >> _final = None >> def __new__(meta, name, bases, ns): >> if meta._final is None: >> meta._final = cls = super().__new__(meta, name, bases, ns) >> return cls >> elif meta._final in bases: # Not sure this check is needed. >> raise TypeError('base class is final and cannot be >> subclassed') > > This will make DoneMeta a one-shot, meaning you'll have to make more > DoneMeta's if you need more than one unsubclassable class. For my purposes, that's enough -- I only have one object that I actually need, something which is like None or Ellipsis or NotImplemented, just a unique and featureless point-particle with no state or behaviour (apart from a neat repr). Yes yes, it's that damn singleton design (anti-)pattern again :-) It's a bit ... something ... that to make a single stateless, behaviourless instance I need a class and a metaclass, but that's Python for you. As an alternative, I may use a single Enum, and delete the class object after I've extracted the enumeration: from enum import Enum class DoneType(Enum): DONE = 'Done' DONE = DoneType(DONE) del DoneType Although enumerations have more behaviour than I need, maybe this is close enough that I don't care. >> class DoneType(metaclass=DoneMeta): >> __slots__ = () >> _instance = None >> def __new__(cls): >> if cls._instance is None: >> cls._instance = inst = super().__new__(cls) >> return inst >> return cls._instance >> def __repr__(self): >> return '' > > And this has to do with single instances, which is not what you asked > about. Very observant of you :-) > Here's some sample code that creates a Final class; any class that > subclasses from it cannot be further subclassed: Thanks. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python 3.6 Installation
On 01/17/2017 03:31 PM, Terry Reedy wrote: > On 1/17/2017 1:23 PM, Earl Izydore wrote: >> I having problems installing Python 3.6. I was using Python 2.7 >> successfully. >> >> Today, I installed python-3.6.0.exe. > > Which binary? from where? > >> At the end of the installation I got a message saying the >> installation was successful. >> >> When attempt to start Python, I get the following Application Error: >> The application was unable to start correctly (0xc07b). Click OK >> to close the application. > > Searching the web for 0xc07b gets many hits and suggestions. For > python, searching stackoverflow.con is probably better. > > https://stackoverflow.com/questions/20650596/cannot-open-python-error-0xc07b > > is only one of the hits. > >> I am using Windows 7 Professional, 64 bit. Yes googling error messages is a good idea. However the SO link seems to describe this problem as a missing DLL, probably the VS 2015 runtime redistributable library. If this is the problem, why isn't Python's installer bundling the runtime for optional install? Many other installers do this. Judging by the frequency of posts like this one to this list, it's a problem that affects more than a few users. Anyway, it seems like this kind of runtime error is cropping up more and more for folks. -- https://mail.python.org/mailman/listinfo/python-list
Re: Emulating Final classes in Python
On Tuesday 17 January 2017 20:37, Antoon Pardon wrote: > Op 17-01-17 om 08:05 schreef Steven D'Aprano: >> I wish to emulate a "final" class using Python, similar to bool: >> >> py> class MyBool(bool): >> ... pass >> ... >> Traceback (most recent call last): >> File "", line 1, in >> TypeError: type 'bool' is not an acceptable base type [...] > I find those kind of classes annoying as hell and nobody has ever given me a > good reason for them. What good was it to change Lock from a factory function > to a class if you can't subclass the result anyway. I'm not sure which Lock class you're referring to. > The result will probably be that users that would prefer to subclass your > class will monkey-patch it. Something like: > > class MyLock: > def __init__(self): > self.lock = Lock() > > def __getattr__(self, attr): > return getattr(self.lock, attr) That technique is called "delegation", or sometimes "composition". > So I wonder what reasons do you have prefering that your users monkey-patch > your class instead of subclassing it? Since my class provides no useful behaviour, I don't think anyone will seriously have any reason to subclass it. Python has at least three singleton instances which are used purely as abstract symbols: they have no state, and very little behaviour besides a nice repr. They are None, NotImplemented and Ellipsis. I'm effectively trying to make my own abstract symbol. But it's mostly a learning exercise. -- Steven "Ever since I learned about confirmation bias, I've been seeing it everywhere." - Jon Ronson -- https://mail.python.org/mailman/listinfo/python-list
Re: Python 3.6 Installation
On Wednesday 18 January 2017 12:30, Michael Torrie wrote: > Yes googling error messages is a good idea. However the SO link seems to > describe this problem as a missing DLL, probably the VS 2015 runtime > redistributable library. If this is the problem, why isn't Python's > installer bundling the runtime for optional install? Many other > installers do this. Judging by the frequency of posts like this one to > this list, it's a problem that affects more than a few users. > > Anyway, it seems like this kind of runtime error is cropping up more and > more for folks. Perhaps some Python-on-Windows user who cares about this issue should raise it on the bug tracker as a feature request. -- Steven "Ever since I learned about confirmation bias, I've been seeing it everywhere." - Jon Ronson -- https://mail.python.org/mailman/listinfo/python-list
Re: Python 3.6 Installation
On 01/17/2017 07:12 PM, Steven D'Aprano wrote: > On Wednesday 18 January 2017 12:30, Michael Torrie wrote: > >> Yes googling error messages is a good idea. However the SO link seems to >> describe this problem as a missing DLL, probably the VS 2015 runtime >> redistributable library. If this is the problem, why isn't Python's >> installer bundling the runtime for optional install? Many other >> installers do this. Judging by the frequency of posts like this one to >> this list, it's a problem that affects more than a few users. >> >> Anyway, it seems like this kind of runtime error is cropping up more and >> more for folks. > > Perhaps some Python-on-Windows user who cares about this issue should raise > it > on the bug tracker as a feature request. I did a quick search of the issue tracker and now I'm confused. Apparently the installer does bundle the runtime with Python. And if Python is compiled against this new MS universal runtime that is supposed to be in all supported versions of windows (from windows update) why is Visual Studio 2015 redistributable required, as per the SO link Terry linked to? http://bugs.python.org/issue28592 -- Erik mentions that the runtime is bundled with the installer, but probably shouldn't be since it's a windows update thing now... -- https://mail.python.org/mailman/listinfo/python-list
Re: Emulating Final classes in Python
On 01/17/2017 01:37 AM, Antoon Pardon wrote: Op 17-01-17 om 08:05 schreef Steven D'Aprano: I wish to emulate a "final" class using Python, similar to bool: py> class MyBool(bool): ... pass ... Traceback (most recent call last): File "", line 1, in TypeError: type 'bool' is not an acceptable base type I find those kind of classes annoying as hell and nobody has ever given me a good reason for them. Subclassing an Enum that has members can be confusing -- subclassed members pass isinstance checks but fail to show up in the parent class' iteration. Subclassing a new data type, such as one with Yes, No, and Maybe, with lots of code dealing explicitly with those three singletons, would be confusing if not outright broken. Both those cases are good candidates for disallowing subclassing. -- ~Ethan~ -- https://mail.python.org/mailman/listinfo/python-list
Re: Python 3.6 Installation
On 1/17/2017 11:32 PM, Michael Torrie wrote: On 01/17/2017 07:12 PM, Steven D'Aprano wrote: On Wednesday 18 January 2017 12:30, Michael Torrie wrote: Yes googling error messages is a good idea. However the SO link seems to describe this problem as a missing DLL, probably the VS 2015 runtime redistributable library. If this is the problem, why isn't Python's installer bundling the runtime for optional install? Many other installers do this. Judging by the frequency of posts like this one to this list, it's a problem that affects more than a few users. Anyway, it seems like this kind of runtime error is cropping up more and more for folks. Perhaps some Python-on-Windows user who cares about this issue should raise it on the bug tracker as a feature request. I did a quick search of the issue tracker and now I'm confused. Apparently the installer does bundle the runtime with Python. And if Python is compiled against this new MS universal runtime that is supposed to be in all supported versions of windows (from windows update) Not everyone has run Windows update since the current runtime was released. why is Visual Studio 2015 redistributable required, as per the SO link Terry linked to? http://bugs.python.org/issue28592 -- Erik mentions that the runtime is bundled with the installer, but probably shouldn't be since it's a windows update thing now... -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: Emulating Final classes in Python
On Wednesday 18 January 2017 15:42, Ethan Furman wrote: [...] > Both those cases are good candidates for disallowing subclassing. I've given a metaclass that disallows subclassing: class MyClass(MyParent, metaclass=FinalMeta): ... Ethan took that one step further by giving a class you inherit from to disallow subclassing: class MyClass(MyParent, Final): ... Could we solve this problem with a decorator? @final class MyClass(MyParent): ... Without needing to add any special magic to MyParent or MyClass, apart from the decorator, can we make MyClass final? That would (in principle) allow us to make a subclass, and *then* set the class final so that no more subclasses could be made. I thought that the decorator could simply set the class' metaclass: def final(cls): if cls.__class__ is type: cls.__class__ = Meta return cls raise TypeErrror('Possible metaclass conflict') but that's disallowed. Any ideas? -- Steven "Ever since I learned about confirmation bias, I've been seeing it everywhere." - Jon Ronson -- https://mail.python.org/mailman/listinfo/python-list