[Python-Dev] Why doesn't `functools.total_ordering` use the existing ordering methods?

2011-04-25 Thread cool-RR
Hello,

Today I was trying to use `total_ordering` for the first time. I was
expecting that in order to implement e.g. `x > y` it would do `not x < y and
not x == y`, assuming that `__lt__`  and `__eq__` are defined. But I see it
just does `y < x`, which is problematic. For example if you have a class
that is decorated by `total_ordering`, and implements only `__lt__`  and
`__eq__`, then trying to do `x < y` will result in infinite recursion.

Why not have `total_ordering` work in the way I suggested?


Ram.
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Why does TemporaryDirectory not wait for `__enter__`?

2011-02-26 Thread cool-RR
On Sat, Feb 26, 2011 at 4:39 PM, Nick Coghlan  wrote:

> On Sat, Feb 26, 2011 at 10:52 PM, cool-RR  wrote:
> > Hello,
> > I noticed that the `TemporaryDirectory` context manager creates the
> folder
> > on `__init__` rather than on `__enter__`, resulting in complexity, bugs,
> and
> > hackarounds in `__del__`. I assume there's a good reason for this
> decision.
> > What is it?
>
> From the docstring: "This has the same behavior as mkdtemp but can be
> used as a context manager." Like files, it *can* be used as a context
> manager, but doesn't have to be.
>
> Also, the complexity wouldn't go away even if the directory creation
> was delayed until the __enter__ invocation. People can still call
> __enter__ directly, so __del__ would still be obliged to try to clear
> things up as best it could.
>
> Cheers,
> Nick.


I think that if someone calls `__enter__` directly, he takes the
responsibility of calling `__exit__`, so we don't really have to help him
with `__del__`.

But other than that I understand the motivation for making it start on
`__init__` rather then `__enter__`. I'll just make my own version of it that
will work on `__enter__` instead.

Thanks,
Ram.
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


[Python-Dev] Why does TemporaryDirectory not wait for `__enter__`?

2011-02-26 Thread cool-RR
Hello,

I noticed that the `TemporaryDirectory` context manager creates the folder
on `__init__` rather than on `__enter__`, resulting in complexity, bugs, and
hackarounds in `__del__`. I assume there's a good reason for this decision.
What is it?


Thanks,
Ram.
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


[Python-Dev] Generating "canonical argument call" from `getargspec` and `getcallargs` results

2010-08-24 Thread cool-RR
I was happy to see the new `getcallargs` function in the `inspect` module.
But there's one thing I want to do that's related to it, and maybe this was
implemented somewhere or someone can give me some pointers about it.

I want to have a function that takes the results of `getargspec` and
`getcallargs` for a function and a set of arguments, and outputs the
"canonical argument call" that would generate these results.

For example, let's say I have a function `f`:

def f(a, b, c=7, **kwargs):
pass

This is its argument spec:

>>> inspect.getargspec(f)
ArgSpec(args=['a', 'b', 'c'], varargs=None, keywords='kwargs',
defaults=(7,))

Now, different argument combinations can generate the same results
`getcallargs` result

>>> inspect.getcallargs(f, 1, 2, 7, meow='grrr') # Like calling f(1, 2,
7, meow='grrr')
{'a': 1, 'c': 7, 'b': 2, 'kwargs': {'meow': 'grrr'}}

>>> inspect.getcallargs(f, 1, 2, meow='grrr') # Like calling f(1, 2,
meow='grrr')
{'a': 1, 'c': 7, 'b': 2, 'kwargs': {'meow': 'grrr'}}

>>> inspect.getcallargs(f, 1, b=2, c=7, meow='grrr') # Like calling f(1,
b=2, c=7, meow='grrr')
{'a': 1, 'c': 7, 'b': 2, 'kwargs': {'meow': 'grrr'}}

What I would like to have is one canonical argument combination. I assume
that the best way to define the canonical form is "The smallest number of
arguments, and specifying as few keyword arguments as possible." According
to that definition, the canonical argument call in the above example would
be the second one, `f(1, 2, meow='grrr')`.

So I want a function that for a given function and argument call, returns
the canonical argument call, which generates the same `getcallargs` result
as the given argument call.

The reason I want this is to make it easier to organize a set of argument
calls. (I'm doing an application in which the user maintains a set of
argument profiles that he can choose from, and having to deal with only the
canonical form will prevent some annoyances.)

Did anyone implement something like this? Does anyone have ideas? And is
this something that would be of interest to the standard library?


Best Wishes,
Ram Rachum.
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Tkinter has many files

2009-08-06 Thread cool-RR
>
> Why do you need to keep the whole Python distribution under version
> control? Isn't all you need a script to *generate* the py2exe'd output from
> an *installed* Python? This is the approach I take with Movable Python which
> does something very similar.
>
>
Never mind the source control issue, it's minor.

If it's not possible to minimize the number of files there, I guess I'll
have to live with it.


-- 
Sincerely,
Ram Rachum
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


[Python-Dev] Tkinter has many files

2009-08-06 Thread cool-RR
Hello python-dev!

I'm a Python programmer, but this is the first time I'm posting on
python-dev, and I am not familiar at all with how the Python implementation
works -- so this post may be way off.

I've recently released a Python application,
PythonTurtle,
which is packaged using py2exe and InnoSetup. Due to the fact that my
program needs to give the user a full Python shell, I've made py2exe package
the entire Python standard library with my application. What I've noticed
when I did that is that Tkinter has *a lot* of files. This is a bit
inconvenient for several reasons, the main one being that the installer for
PythonTurtle takes a long time to copy all of those little files. (I think
the reason for the slowness is not the weight of the files, but the fact
that there are so many of them.) There are also other reasons why it's
annoying: Ohloh thinks my project is "Mostly written in Tcl," and git-gui
gave me trouble for trying to commit so many files.
Do you think it will be a good thing to package all of these Tkinter files
into one big file (or several big files)?

Best Wishes,
Ram Rachum.
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com