New submission from George Sakkis <[EMAIL PROTECTED]>:
I'd like to propose a new function for inclusion to the inspect module
-- getcallargs(func, *args, **kwds) -- that returns a dict which maps
the formal arguments of a function (or other callable) to the values
passed as args and
New submission from George Sakkis :
The following exception message seems misleading, or at least not obvious:
>>> def f(a,b,c): pass
...
>>> f(c=0,a=0)
Traceback (most recent call last):
File "", line 1, in
TypeError: f() takes exactly 3 non-keyword arguments (1
George Sakkis added the comment:
I reverted the function to the original API (return just the dict with the
bindings), cleaned it up, wrote thorough unit tests and made a patch against
Python 2.7a4.
--
keywords: +patch
Added file: http://bugs.python.org/file16579/getcallargs.patch
Changes by George Sakkis :
Removed file: http://bugs.python.org/file16579/getcallargs.patch
___
Python tracker
<http://bugs.python.org/issue3135>
___
___
Python-bug
George Sakkis added the comment:
Renamed the Testcase classes to conform with the rest in test_inspect.py, added
a few more tests for tuple args and patched against the latest trunk (r79086).
--
Added file: http://bugs.python.org/file16587/getcallargs.patch
George Sakkis added the comment:
Which version are you running ? I don't get the "positional" word in 2.6 and
2.7a4.
In my opinion it should report how many required arguments are passed,
regardless of how they are passed (positionally or by name). So in your example
it shou
George Sakkis added the comment:
Attached patch for displaying the number of missing required arguments.
--
keywords: +patch
Added file: http://bugs.python.org/file16589/6474.patch
___
Python tracker
<http://bugs.python.org/issue6
George Sakkis added the comment:
- Added docs in inspect.rst
- Fixed TypeError message for zero-arg functions ("takes no arguments" instead
of "takes exactly 0 arguments") + added test.
--
Added file: http://bugs.python.org/file1659
George Sakkis added the comment:
Uploaded at http://codereview.appspot.com/659041/show
--
___
Python tracker
<http://bugs.python.org/issue3135>
___
___
Python-bug
George Sakkis added the comment:
Is there any update on this for 2.7 ?
--
nosy: +gsakkis
___
Python tracker
<http://bugs.python.org/issue1745>
___
___
Python-bug
George Sakkis added the comment:
FWIW I updated the patch to r79264; it applies cleanly and passes the tests but
other than that I can't tell if it's ready. It would be nice to have it in 2.7
though.
--
Added file:
http://bugs.python.org/file16618/backport-keyword-only
George Sakkis added the comment:
Just bitten by this (through a 3rd party library that uses this pattern) and
I'm wondering why it was closed as invalid. Passing a non-empty fromlist string
also imports the tail module but without the side effect of double import, so
it's not
George Sakkis added the comment:
> When you use an empty string in fromlist you are essentially simulating
> ``from pkg import`` which makes absolutely no sense, so no one has
> cared enough to try to fix this.
``from pkg import __bogus__, 123, @$%`` doesn't make sense eith
George Sakkis added the comment:
More fun findings: dots are special-cased too, but only if they don't appear
consecutively (!);
~$ cat pkg/__init__.py
print __name__
~$ python -c "__import__('pkg', fromlist=['.'])"
pkg
pkg..
~$ python -c "__import_
George Sakkis added the comment:
FWIW attached is a patch that allows only valid identifiers before calling
import_submodule(), and returns silently otherwise (for backwards
compatibility).
For the record, the reason that empty strings and some combinations of
slashes/dots caused the double
George Sakkis added the comment:
> On the surface this seems like a potential directory traversal attack
> hole, although I couldn't get past 'pkg' by passing '../../../', so I
> guess there must be other checks before attempting the import.
I rushed to p
George Sakkis added the comment:
Just discovered this by chance; I would probably have noticed it earlier if the
docstring had been updated. Let me know if it needs a new documentation bug
ticket and I'll create one.
Pretty handy feature by the way, thanks for adding it!
--
New submission from George Sakkis :
Not sure if this has been brought before but how about extending getargspec to
work with callable instances, i.e. make it equivalent to
getargspec(obj.__call__) ?
--
components: Library (Lib)
messages: 105166
nosy: gsakkis
priority: normal
severity
George Sakkis added the comment:
Agreed; package_data are also ignored by sdist. Unfortunately, neither
setuptools seems to work as expected on sdist but at least bdist_egg does.
MANIFEST.in is an ugly hack and should be deprecated; you shouldn't have
to repeat yourself in two
George Sakkis added the comment:
I didn't mean to imply that automagic discovery based on external
version control software is better than MANIFEST.in; I favor
explicitness here as well. It's just that this information can (and
often has to) be duplicated in setup.py as 'p
George Sakkis added the comment:
By an equivalent option in setup() of course. I'm not against the
*functionality* of MANIFEST.in but on that (a) it's a second file you
have to remember to write and maintain in addition to setup.py (b) has
its own ad-hoc syntax instead of pyt
New submission from George Sakkis :
ThreadPoolExecutor.map() prevents interpreter exit if there is a reference to
the generator it returns. In the attached script:
- `python threadpool_map.py run1` exits as soon as the exception is raised on
the main thread. This is the desired behavior in
New submission from George Sakkis :
I'd like to propose two new optional boolean parameters to the @dataclass()
decorator, `asdict` and `astuple`, that if true, the respective methods are
generated as equivalent to the module-level namesake functions.
In addition to saving an extra imp
George Sakkis added the comment:
> I think the best thing to do is write another decorator that adds this
> method. I've often thought that having a dataclasses_tools third-party module
> would be a good idea.
I'd be happy with a separate decorator in the standard libra
George Sakkis added the comment:
> > FWIW I wrote a module that overrides the default build_py and sdist
> > commands with versions that allow specifying package_data recursively
>
> Maybe that could be a new feature ?
That would be nice, especially if we want to reimplem
George Sakkis added the comment:
> done in r69692 and r69696.
Great, thanks. The data_files part though seems incorrect; for one thing
each item in data_files can be either a (dir,files) tuple or a plain
string, and for two 'dir' is the output (installation) directory, not
the r
New submission from George Sakkis :
Distutils ignores file permissions when copying modules and package_data
files to the build directory, and consequently to the installation
directory too. According to an XXX comment at
distutils/command/build_py.py, this is deliberate so that the built
files
New submission from George Sakkis :
Currently each glob defined in package_data must match files only; if it
matches a directory, it raises an exception later when calling
copy_file(). This means that a glob like 'mydata/*' will fail if there
is any subdirectory under 'mydata'
George Sakkis added the comment:
Opened #5300 and #5302 for the mentioned issues.
Btw in your patch, I believe `os.path.join(dirname, f)` should be
replaced by `f` alone; `dirname` refers to the dir under the
installation directory, not the source
George Sakkis added the comment:
> I am no in favor of MANIFEST.in removal because I find it very
> convenient to define what is included in a package and I rarely use
> package_data or data_files.
AFAIK the MANIFEST is used only by sdist; what's the point of including
files
George Sakkis added the comment:
> what is your use case of having executable file here ?
>
> I'd use the 'scripts' metadata for that ?
For one thing they are external binaries, not python scripts, and second
they are used internally only (through Subprocess), the
New submission from George Sakkis :
It would be useful in many cases if heapq.nlargest and heapq.nsmallest
grew an optional boolean parameter, say `ties` (defaulting to False)
that when True, it would return more than `n` items if there are ties.
To illustrate:
>>> s = [4,3,5,7,4,7,4,3
George Sakkis added the comment:
The second call should of course be:
>>> for i in xrange(1,len(s)+1): print i,heapq.nsmallest(i,s,ties=True)
--
___
Python tracker
<http://bugs.python.o
Changes by George Sakkis :
--
title: Extra heap nlargest/nsmallest option for including ties -> Extra heapq
nlargest/nsmallest option for including ties
___
Python tracker
<http://bugs.python.org/iss
George Sakkis added the comment:
There's nothing special about my use cases; I'd even go as far as to
suggest that this is more often than not the desired behavior in general.
Say that you have to select the top 3 chess players and there are two
players with equal Elo rating at posit
George Sakkis added the comment:
> In that case, I think it best to leave nsmallest/nlargest as-is. By
> appending ties to the result, it becomes harder to implement policy
> decisions on what to do with those ties (perhaps listing them separately
> or splitting their prizes n
George Sakkis added the comment:
> That should have been: last = result[-1]; [last]*s.count(last).
Nice, though that's not equivalent if the objects' identity is
significant for what happens next (which typically is the case when ties
are preserved). The sorted/bisect solution
Changes by George Sakkis :
--
status: open -> closed
___
Python tracker
<http://bugs.python.org/issue5669>
___
___
Python-bugs-list mailing list
Unsubscri
George Sakkis added the comment:
> I recommend posting an ASPN recipe. That's what I do with a lot of
> ideas that are under development or that don't clear the bar for going
> into the standard library.
Will do. Thanks for t
New submission from George Sakkis :
According to the docs, heapq.nlargest should be equivalent to
sorted(iterable, key=key, reverse=True)[:n], and since sorted() is
stable, so should heapq.nlargest be. This is not the case:
>>> s =[
('Mike', -1),
('John', 3)
George Sakkis added the comment:
Posted recipe at http://code.activestate.com/recipes/576712/. You were
right, the implementation gets significantly hairier but I think it's
worth having this option. It's also faster than using sorted/bisect as
len(seq)/N increases and t
George Sakkis added the comment:
Should have checked a recent version first; that's from 2.5 (r25:51908,
Sep 19 2006, 09:52:17). Sorry for the noise.
--
status: open -> closed
___
Python tracker
<http://bugs.python.or
New submission from George Sakkis :
Is the following behavior expected ?
class MyProp(property):
pass
class Foo(object):
@property
def bar(self):
'''Get a bar.'''
@MyProp
def baz(self):
'''Get a baz.''
New submission from George Sakkis :
It would be nice if classmethod/staticmethod exposed the wrapped
function as a read-only attribute/property. Currently the function can
be retrieved indirectly but it's obscure (and perhaps not always
correct, I'm not sure):
In [147]: de
George Sakkis added the comment:
I updated the recipe to also return a `missing_args` tuple - the tuple
of the formal parameters whose value was not provided. This is useful in
cases where one want to distinguish f() from f(None) given "def f(x=None)".
--
versions: +Python 2
George Sakkis added the comment:
Also updated url: http://code.activestate.com/recipes/551779/
--
___
Python tracker
<http://bugs.python.org/issue3135>
___
___
George Sakkis added the comment:
I don't remember the exact use case but it had to do with making a
decorator robust enough to work for different kinds of callables (and a
few common non-callables such as classmethod/staticmethod). It's not a
show stopper by any means but I thought i
47 matches
Mail list logo