Re: __new__() does not return anything, on singletong pattern

2015-03-12 Thread Mario Figueiredo
On Thu, 12 Mar 2015 22:04:30 +1100, Steven D'Aprano wrote: > >3-4 seconds to instantiate is a bit worrying, but you should look at >improving the efficiency of loading a map rather than insisting that there >should be only one map instance. Particularly in the map editor, what if >the user wants

Re: __new__() does not return anything, on singletong pattern

2015-03-12 Thread Mario Figueiredo
On Thu, 12 Mar 2015 21:41:16 +1300, Gregory Ewing wrote: >Mario Figueiredo wrote: >> But PyCharm flags the assignment >> with a warning telling me that generate() does not return anything and >> the I lose code completion on the mmap variable. > >My guess is that there is a syntax error somewhere

Re: __new__() does not return anything, on singletong pattern

2015-03-12 Thread Mario Figueiredo
On Thu, 12 Mar 2015 22:29:24 +1100, Steven D'Aprano wrote: > >I would have a loadfile() method which takes a filename on disk, opens the >file and passes the contents (or the open file object) to another method, >load() to do the actual work: > > >class Map: >def __new__(cls, width, height, f

Re: __new__() does not return anything, on singletong pattern

2015-03-12 Thread Steven D'Aprano
Mario Figueiredo wrote: > On Thu, 12 Mar 2015 16:31:12 +1100, Steven D'Aprano > wrote: > >>Mario Figueiredo wrote: >> >> >>If this is supposed to be a singleton, you can't create more instances. >>The point of a singleton that there is only one instance (or perhaps a >>small number, two or three

Re: __new__() does not return anything, on singletong pattern

2015-03-12 Thread Steven D'Aprano
Mario Figueiredo wrote: > It's just a cheap global, since is ubiquitous throughout the entire > application, does behave like a singleton, and is a bit too expensive > to create. A full map in the main application takes 3 or 4 seconds to > instantiate and occupies around 2 Mb of memory. 2MB is no

Re: __new__() does not return anything, on singletong pattern

2015-03-12 Thread Mario Figueiredo
On Thu, 12 Mar 2015 21:40:03 +1300, Gregory Ewing wrote: >Mario Figueiredo wrote: > >> A different application, a map editor, needs to also instantiate an >> object of the class Map. But in this case the map needs to either be >> empty (if the user wants to create a new map), or loaded from the >

Re: __new__() does not return anything, on singletong pattern

2015-03-12 Thread Mario Figueiredo
On Thu, 12 Mar 2015 21:38:00 +1300, Gregory Ewing wrote: > >I would just provide a function: > >_map = None > >def get_map(): >global _map >if _map is None: > _map = Map() >return _map > >and document the fact that you shouldn't call Map() >directly. Oh, you are so right! Been

Re: __new__() does not return anything, on singletong pattern

2015-03-12 Thread Gregory Ewing
Mario Figueiredo wrote: But PyCharm flags the assignment with a warning telling me that generate() does not return anything and the I lose code completion on the mmap variable. My guess is that there is a syntax error somewhere in your code that's confusing the IDE. -- Greg -- https://mail.pyt

Re: __new__() does not return anything, on singletong pattern

2015-03-12 Thread Gregory Ewing
Mario Figueiredo wrote: A different application, a map editor, needs to also instantiate an object of the class Map. But in this case the map needs to either be empty (if the user wants to create a new map), or loaded from the saved map file (if the user wants to edit an existing map). Then yo

Re: __new__() does not return anything, on singletong pattern

2015-03-12 Thread Gregory Ewing
Mario Figueiredo wrote: It's just a cheap global, since is ubiquitous throughout the entire application, does behave like a singleton, and is a bit too expensive to create. A full map in the main application takes 3 or 4 seconds to instantiate and occupies around 2 Mb of memory. There's nothin

Re: __new__() does not return anything, on singletong pattern

2015-03-12 Thread Mario Figueiredo
On Wed, 11 Mar 2015 16:47:32 -0700, Ethan Furman wrote: > >You're code is good. Thanks for taking a weight off my shoulder. > > The only question is if you /really/ need a singleton -- and only > you can answer that (although plenty of folks will tell you you > don't ;) . Yeah. I debated that

Re: __new__() does not return anything, on singletong pattern

2015-03-12 Thread Mario Figueiredo
On Thu, 12 Mar 2015 16:31:12 +1100, Steven D'Aprano wrote: >Mario Figueiredo wrote: > > >If this is supposed to be a singleton, you can't create more instances. The >point of a singleton that there is only one instance (or perhaps a small >number, two or three say). Why do you need two differen

Re: __new__() does not return anything, on singletong pattern

2015-03-11 Thread Steven D'Aprano
Mario Figueiredo wrote: > I'm fairly new to Python, so I don't know if the following is me > abusing the programming language idioms, or simply a mistake of my IDE > code inspection routine. > > I have a singleton Map class which is defined like so: > > class Map: > _instance = None > de

Re: __new__() does not return anything, on singletong pattern

2015-03-11 Thread Ethan Furman
On 03/11/2015 04:33 PM, Mario Figueiredo wrote: > The following code runs just fine. But PyCharm flags the assignment > with a warning telling me that generate() does not return anything and > the I lose code completion on the mmap variable. > > if __name__ == '__main__': > mmap = Map.generat

__new__() does not return anything, on singletong pattern

2015-03-11 Thread Mario Figueiredo
I'm fairly new to Python, so I don't know if the following is me abusing the programming language idioms, or simply a mistake of my IDE code inspection routine. I have a singleton Map class which is defined like so: class Map: _instance = None def __new__(cls): if Map._instan