🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: pl.comp.lang.python
5 messages
5 total messages Started by max Thu, 23 Sep 2010 13:27
Ile funkcja ma parametrów i "Predefined Completions" PyDev
#27678
Author: max
Date: Thu, 23 Sep 2010 13:27
39 lines
2274 bytes
Mały przykład:
import math
a = dir(math)
print(a)

['__doc__', '__name__', '__package__', 'acos', 'acosh', 'asin', 'asinh', 
'atan', 'atan2', 'atanh', 'ceil', 'copysign', 'cos', 'cosh', 'degrees', 
'e', 'exp', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 
'hypot', 'isinf', 'isnan', 'ldexp', 'log', 'log10', 'log1p', 'modf', 
'pi', 'pow', 'radians', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'trunc']


Jak teraz dla każdej funkcji (o ile to jest funkcja)
sprawdzić ile ma parametrów , ewentualnie jakie.

Co chcę uzyskać, bo może można to zrobić inaczej:
Chodzi mi o wygenerowanie niby kodu pythona któpry można by było użyc 
potem w pyDev  "Predefined Completions"
http://pydev.org/manual_101_interpreter.html

"Predefined completions are completions acquired from sources that 
provide only the interfaces for a given Python module (with Python 3.0 
syntax).

A predefined completion module may be created by having a module with 
the extension ".pypredef" with regular Python 3.0 contents, but with 
attributes having assigns to its type and methods having as the body a 
sole return statement -- and the docstring may have anything.

Example for a my.source.module (must be declared in a 
my.source.module.pypredef file):"

Oczywiście dla math nie ma to najmniejszego sensu
ale w przypadku gdy mamy moduł dla którego nie ma kodu
a chcieli byśmy mieć code-completion.



M
Re: Ile funkcja ma parametrów i "Predefined Completions" PyDev
#27679
Author: Wojciech Muła
Date: Thu, 23 Sep 2010 13:51
20 lines
1604 bytes
max <max@max.pl> wrote:

> Mały przykład:
> import math
> a = dir(math)
> print(a)
> 
> ['__doc__', '__name__', '__package__', 'acos', 'acosh', 'asin', 'asinh', 
> 'atan', 'atan2', 'atanh', 'ceil', 'copysign', 'cos', 'cosh', 'degrees', 
> 'e', 'exp', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 
> 'hypot', 'isinf', 'isnan', 'ldexp', 'log', 'log10', 'log1p', 'modf', 
> 'pi', 'pow', 'radians', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'trunc']
> 
> Jak teraz dla każdej funkcji (o ile to jest funkcja)
> sprawdzić ile ma parametrów , ewentualnie jakie.

Moduł inspect, funkcja getargspec:
http://docs.python.org/library/inspect.html?highlight=inspect#inspect.getargspec

w.
Re: Ile funkcja ma parametrów i "Predefined Completions" PyDev
#27680
Author: max
Date: Thu, 23 Sep 2010 14:12
12 lines
1423 bytes
>
> Moduł inspect, funkcja getargspec:
> http://docs.python.org/library/inspect.html?highlight=inspect#inspect.getargspec
>
> w.

To działa tylko dla funkcji zadeklarowanych w python
jak to jest "built-in"
funckja inspect.isbuiltin dla obiektu  zwraca TRUE
to już getargspec nie działa

M
Re: Ile funkcja ma parametrów i "Predefined Completions" PyDev
#27681
Author: Wojciech Muła
Date: Thu, 23 Sep 2010 14:20
12 lines
1367 bytes
max <max@max.pl> wrote:

> To działa tylko dla funkcji zadeklarowanych w python
> jak to jest "built-in"
> funckja inspect.isbuiltin dla obiektu  zwraca TRUE
> to już getargspec nie działa

Więc chyba nic nie zrobisz - http://bugs.python.org/issue1748064
"The signature of functions implemented in C is currently not
exposed to introspection".

w.
Re: Ile funkcja ma parametrów i "Predefined Completions" PyDev
#27682
Author: max
Date: Thu, 23 Sep 2010 14:45
20 lines
1907 bytes
W dniu 2010-09-23 16:20, Wojciech Muła pisze:
> max<max@max.pl>  wrote:
>
>> To działa tylko dla funkcji zadeklarowanych w python
>> jak to jest "built-in"
>> funckja inspect.isbuiltin dla obiektu  zwraca TRUE
>> to już getargspec nie działa
>
> Więc chyba nic nie zrobisz - http://bugs.python.org/issue1748064
> "The signature of functions implemented in C is currently not
> exposed to introspection".
>
> w.
Chyba masz rację , w innym miejscu znalazłem mniej wiecej to samo co 
napisałeś

Nawet znalazłem plik do generowania "Predefined Completions"
ale nie zadziała niestety

http://xbmc-pydev-predefcom.googlecode.com/svn/trunk/script.pypredefcom/resources/lib/pypredefcom.py
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads