Re: Creating type evaluation annotation

2018-12-10 Thread Marek Mosiewicz
W dniu 09.12.2018, nie o godzinie 15∶50 -0500, użytkownik Terry Reedy
napisał:
> 
> Mypy recognizes this sublanguage to 'compute' whether calls conform
> to 
> the defined interfaces.
> 
As far as I understand currently it computes if declaration commits to
static type. What I propose is to annotate type with "duck" typing
checker and futher it could make suggester for duck typing. We can
imagine duck typing suggester for imaginary entity class which accepts
finders like in Ruby on rails : "find_by_name" "find_by_id"
"find_by_name_and_something"

Then when you type "find_" it will suggest futher method name. When you
finish typing "find_by_name_and_length" for example it will force you
to put two paramters of type string and int
> 
> -- 
> Terry Jan Reedy
> 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Creating type evaluation annotation

2018-12-09 Thread Terry Reedy

On 12/9/2018 11:37 AM, Jon Ribbens wrote:

On 2018-12-09, Marek Mosiewicz  wrote:

I'm talking about this https://docs.python.org/3/library/typing.html

I'm not talking about new language. I think it could be nice to have
standard PEP annotations for classes to make type validation or type
hints when writing code.



This class valiadtors would be optional and run only when developer
wants to validate or write code, not in production as it is heavy.



Yes, I think that's exactly what http://www.mypy-lang.org/ is.
It is not a new language,


All libraries extend the language by adding names that python 
recognizes.  The typing additions are more like a new sublanguage than 
most in that the new objects are not for computation in the traditional 
sense but for representation of concepts.


Mypy recognizes this sublanguage to 'compute' whether calls conform to 
the defined interfaces.



despite the rather strange choice of domain name for it.


mypy.org is a 'parked' domain name for sale.
mypy.com is a misc tech news site (nothing about Python) dead since Jan 
2014.


I don't know the genesis of the names above, but 'mypy' is a rather 
obvious contraction of 'my py'(thon).  I once had a directory of my 
python scripts called 'mypy', in a directory on sys.path, so I could run 
one with "python -m mypy.scriptname.  I changed my name to not conflict.


--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list


Re: Creating type evaluation annotation

2018-12-09 Thread Jon Ribbens
On 2018-12-09, Marek Mosiewicz  wrote:
> I'm talking about this https://docs.python.org/3/library/typing.html
>
> I'm not talking about new language. I think it could be nice to have
> standard PEP annotations for classes to make type validation or type
> hints when writing code. 
...
> This class valiadtors would be optional and run only when developer
> wants to validate or write code, not in production as it is heavy.

Yes, I think that's exactly what http://www.mypy-lang.org/ is.
It is not a new language, despite the rather strange choice of
domain name for it.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Creating type evaluation annotation

2018-12-09 Thread Marek Mosiewicz
I'm talking about this https://docs.python.org/3/library/typing.html

I'm not talking about new language. I think it could be nice to have
standard PEP annotations for classes to make type validation or type
hints when writing code. 

It would be best of two worlds. Dynamic language with optional type
chceking if somebody wants it. 

In Groovy language there is annotation to indicate that you can not
make calls to methods which do not exist.

It could go futher and you could have annotation which validates
whatever method signature if it is valid. For example you can have
valiadator for something like Ruby on Rails in Ruby language for
methods which starts with find:
invoice.find_by_name
invoice.find_by_name_and_description

It could be even better and give you type hints when you type
method name. In this example when you write in IDE:
invoice.find_by_
it would suggest you futher possible method parts and possible
parameters for method.

This class valiadtors would be optional and run only when developer
wants to validate or write code, not in production as it is heavy.



W dniu 06.12.2018, czw o godzinie 20∶06 +, użytkownik Jon Ribbens
napisał:
> On 2018-12-06, Marek Mosiewicz  wrote:
> > I'm Java developer,but had some experience with Python based
> > ERP software. It is quite serious application and I feel 
> > unconfortable with not having type checking. I do not say language
> > should be static, but having checking method signature
> > is big win. For example in refactoring.
> > I know that Python 3 has possibility to have indicate
> > type for varibale or param
> 
> Are you talking about http://www.mypy-lang.org/ ?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Creating type evaluation annotation

2018-12-06 Thread dieter
Marek Mosiewicz  writes:
> ...
> I know that Python 3 has possibility to have indicate
> type for varibale or param
> What could be great to have possibility to annotate any 
> class with what I call "type evaluator" function.
> That could check method signature with rules specific 
> for given type.
> The simplest evaluator would simply check if signature
> is same as method definition. 
> But it could go futher. It could check whatever is valid 
> logic for creating methods in given class and whatever 
> are valid params for given method.
> Even more powerful evaluator could be not only
> valid/not valid indicator. It could validate
> and suggest next param or method part name for given
> written part of call. That could make python IDEs
> much more powerful
> From my experience having signature checking and
> hinting params when writing code is really big win.

You *can* do all that in Python -- even though you need
something beyond what Python typically comes with.

First, you need a formalisms to describe what should be checked.
There are various alternatives: I am using "zope.interface" (to
describe method signatures) and "zope.schema" (to describe
the "type" of attributes).

Next, you need something that does the checking.
Again, there are alternatives. I prefer to check things
in test suites -- and not permanently during productive use.
But, Python has the powerfull "metaclass" concept.
A metaclass allows you to customize class construction
and e.g. to instrument all defined methods to perform automatic
checks.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Creating type evaluation annotation

2018-12-06 Thread Thomas Jollans
On 06/12/2018 11:48, Marek Mosiewicz wrote:
> I'm Java developer,but had some experience with Python based
> ERP software. It is quite serious application and I feel 
> unconfortable with not having type checking. I do not say language
> should be static, but having checking method signature
> is big win. For example in refactoring.

I get the feeling that you're essentially describing mypy.

> I know that Python 3 has possibility to have indicate
> type for varibale or param
> What could be great to have possibility to annotate any 
> class with what I call "type evaluator" function.
> That could check method signature with rules specific 
> for given type.
> The simplest evaluator would simply check if signature
> is same as method definition. 
> But it could go futher. It could check whatever is valid 
> logic for creating methods in given class and whatever 
> are valid params for given method.
> Even more powerful evaluator could be not only
> valid/not valid indicator. It could validate
> and suggest next param or method part name for given
> written part of call. That could make python IDEs
> much more powerful
> From my experience having signature checking and
> hinting params when writing code is really big win.
> I could simply refactor 10 lines of code in
> Java, but same for Python is much more difficult
> 
> Best regards,
> Marek Mosiewicz
> 
> 

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Creating type evaluation annotation

2018-12-06 Thread Jon Ribbens
On 2018-12-06, Marek Mosiewicz  wrote:
> I'm Java developer,but had some experience with Python based
> ERP software. It is quite serious application and I feel 
> unconfortable with not having type checking. I do not say language
> should be static, but having checking method signature
> is big win. For example in refactoring.
> I know that Python 3 has possibility to have indicate
> type for varibale or param

Are you talking about http://www.mypy-lang.org/ ?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Creating type evaluation annotation

2018-12-06 Thread Terry Reedy

On 12/6/2018 5:48 AM, Marek Mosiewicz wrote:

I'm Java developer,but had some experience with Python based
ERP software. It is quite serious application and I feel
unconfortable with not having type checking. I do not say language
should be static, but having checking method signature
is big win. For example in refactoring.
I know that Python 3 has possibility to have indicate
type for varibale or param
What could be great to have possibility to annotate any
class with what I call "type evaluator" function.
That could check method signature with rules specific
for given type.


This and the following needs simple concrete examples.  Withing such, my 
eyes glaze over.



The simplest evaluator would simply check if signature
is same as method definition.
But it could go futher. It could check whatever is valid
logic for creating methods in given class and whatever
are valid params for given method.
Even more powerful evaluator could be not only
valid/not valid indicator. It could validate
and suggest next param or method part name for given
written part of call. That could make python IDEs
much more powerful
 From my experience having signature checking and
hinting params when writing code is really big win.
I could simply refactor 10 lines of code in
Java, but same for Python is much more difficult

Best regards,
 Marek Mosiewicz





--
Terry Jan Reedy


--
https://mail.python.org/mailman/listinfo/python-list


Creating type evaluation annotation

2018-12-06 Thread Marek Mosiewicz
I'm Java developer,but had some experience with Python based
ERP software. It is quite serious application and I feel 
unconfortable with not having type checking. I do not say language
should be static, but having checking method signature
is big win. For example in refactoring.
I know that Python 3 has possibility to have indicate
type for varibale or param
What could be great to have possibility to annotate any 
class with what I call "type evaluator" function.
That could check method signature with rules specific 
for given type.
The simplest evaluator would simply check if signature
is same as method definition. 
But it could go futher. It could check whatever is valid 
logic for creating methods in given class and whatever 
are valid params for given method.
Even more powerful evaluator could be not only
valid/not valid indicator. It could validate
and suggest next param or method part name for given
written part of call. That could make python IDEs
much more powerful
From my experience having signature checking and
hinting params when writing code is really big win.
I could simply refactor 10 lines of code in
Java, but same for Python is much more difficult

Best regards,
Marek Mosiewicz


-- 
https://mail.python.org/mailman/listinfo/python-list