473,799 Members | 3,134 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Status of optional static typing in Python?

Hi guys,

I'm looking at developing a somewhat complex system, and I think some
static typing will help me keep limit my confusion. I.e.:

http://www.artima.com/weblogs/viewpost.jsp?thread=87182

Does anyone know if/when that feature may become part of Python?

Thanks very much,
Christian
--
Christian Convey
Computer Scientist,
Naval Undersea Warfare Centers
Newport, RI
(401) 832-6824
co******@npt.nu wc.navy.mil
Jun 22 '06 #1
6 1756
Christian Convey a écrit :
Hi guys,

I'm looking at developing a somewhat complex system, and I think some
static typing will help me keep limit my confusion.


Then I think you're suffering from an alas too common delusion. Static
typing (at least declarative static typing) will only makes your system
more complex. But if you want some help in managing complexity, you may
want to look at interfaces systems (Zope3 interfaces or Peak's Protocol)
and multidispatch (Peak's Protocol dispatch package).

Jun 22 '06 #2
Perhaps I'm deluded but I don't think so. I'll tell you my situation
and I'd appreciate your take on it...

I'm looking into the design a network simulator. The simulator has a
few requirements:

(1) I need to be able to swap in a variety of replacement components
during different simulations. I.e., RadioFrequencyC hannelModel,
WiredNetworkCha nnelModel, etc. This drives me to want the notion of
inherited interfaces, partly as a form of documentation.

(2) I want a form of encapsulation (which I realize isn't necessarily
guaranteed in all possible static typing implementations ). I.e., I want
to ensure that any code which accesses a ChannelModel only calls those
methods that are part of the ChannelModel interface. If there's a
method RadioFrequencyC hannelModel.set BroadcastDistan ce(...), which isn't
part of the generic ChannelModel interface, I don't want most of my code
to be able to start using that particular method, if the code need to be
able to work with all possible ChannelModel implementations .

(3) I like Interfaces as a matter of documentation. It helps me to
thing things through. I've got a lot of components that must support
interchangeable implementations : channels, modems, MAC layers, link
layers, etc. If I have an abstract MAC_layer interface, it helps me
think carefully about what every MAC layer ought to provide, and it also
helps me explain to other people what a MAC layer in my simulator must
provide. That is, it helps me better explain to other people how the
system's major components relate to each other.
Now, I could use Java or C# to get functionality such as interfaces, but
I loath giving up the general productive goodness of Python. That's why
I'm looking for something like interfaces.

But even if we disagree about the wisdom of my intentions, do you know
if/when Guido's planning to work that stuff into Python? The last post
I noticed from him on the topic was from 2005. At least back then he
sounded pretty into it.

Thanks,
Christian

Bruno Desthuilliers wrote:
Christian Convey a écrit :
Hi guys,

I'm looking at developing a somewhat complex system, and I think some
static typing will help me keep limit my confusion.


Then I think you're suffering from an alas too common delusion. Static
typing (at least declarative static typing) will only makes your system
more complex. But if you want some help in managing complexity, you may
want to look at interfaces systems (Zope3 interfaces or Peak's Protocol)
and multidispatch (Peak's Protocol dispatch package).


--
Christian Convey
Computer Scientist,
Naval Undersea Warfare Centers
Newport, RI
(401) 832-6824
co******@npt.nu wc.navy.mil
Jun 22 '06 #3
Christian Convey wrote:
Hi guys,

I'm looking at developing a somewhat complex system, and I think some
static typing will help me keep limit my confusion. I.e.:

http://www.artima.com/weblogs/viewpost.jsp?thread=87182

Does anyone know if/when that feature may become part of Python?

Thanks very much,
Christian


It was discussed recently at the Python 3000 mailing list and it seems
that the goals are not very ambitious but this was already clear from
Guidos Artima blog post you cited. So it may happen that type
annotation syntax in function signatures will be introduced in Py3K but
the semantics is reduced to a "protocol" i.e. Python will still be
untyped in a strict sense ( or dynamically type checked to put it more
positive ).

An proposed alternative for type annotation syntax and runtime
type-checks that comes up from time to time is using decorators for
this job.

Here is a recipe that might be usefull in your project right now:

http://aspn.activestate.com/ASPN/Coo.../Recipe/426123

Regards,
Kay

Jun 22 '06 #4
Christian Convey a écrit :
Perhaps I'm deluded but I don't think so.
<after what='having read the rest of the post'>.
You are.
</after>
I'll tell you my situation
and I'd appreciate your take on it...

I'm looking into the design a network simulator. The simulator has a
few requirements:

(1) I need to be able to swap in a variety of replacement components
during different simulations. I.e., RadioFrequencyC hannelModel,
WiredNetworkCha nnelModel, etc. This drives me to want the notion of
inherited interfaces, partly as a form of documentation.
Ok.
(2) I want a form of encapsulation (which I realize isn't necessarily
guaranteed in all possible static typing implementations ). I.e., I want
to ensure that any code which accesses a ChannelModel only calls those
methods that are part of the ChannelModel interface. If there's a
method RadioFrequencyC hannelModel.set BroadcastDistan ce(...), which isn't
part of the generic ChannelModel interface, I don't want most of my code
to be able to start using that particular method, if the code need to be
able to work with all possible ChannelModel implementations .
This is mostly a self-discipline issue. But FWIW, unit-testing should be
enough here. And if you really want something more
bondage-and-discipline, you can use some wrapper object to filter out
the exposed interface. There's very few to do - here's a possible (while
mostly dumb) home-made solution:

class InterfaceType(t ype):
def __new__(meta, class_name, bases, new_attrs):
cls = type.__new__(me ta, class_name, bases, new_attrs)
cls._exposed = [name for name in new_attrs.keys( ) \
if not name.startswith ('_')]
return cls

class Interface(objec t):
__metatype__ = InterfaceType
@classmethod
def _expose(cls, name):
return name in cls._exposed

class InterfaceRestri ctor(object):
def __init__(self, obj, interface):
self._interface = interface
self._obj = obj
def __getattr__(sel f, name):
if self._interface ._expose(name):
return getattr(self._o bj, name)
else:
raise AttributeError( "name %s not allowed" % name)

And you can use a decorator specifying arg names or types -> expected
interface to automagically ensure you get correctly wrapped objects in
the client code.

NB : Don't use that code - here again, object-adaptation (which is at
the core of Zope3 interfaces and Peak's Protocols) comes to mind...
(3) I like Interfaces as a matter of documentation. It helps me to
thing things through. I've got a lot of components that must support
interchangeable implementations :
BTW, did I suggest to have a look at Zope3 interface or Peak's protocols ?-)
channels, modems, MAC layers, link
layers, etc. If I have an abstract MAC_layer interface, it helps me
think carefully about what every MAC layer ought to provide, and it also
helps me explain to other people what a MAC layer in my simulator must
provide. That is, it helps me better explain to other people how the
system's major components relate to each other.
Ok, now this is a design issue. All you need here is an UML-aware
drawing program.
Now, I could use Java or C# to get functionality such as interfaces, but
I loath giving up the general productive goodness of Python. That's why
I'm looking for something like interfaces.
Given your motivations and requirements (which seems pretty sensible
AFAIC), you definitively want to have a look at Zope3 Interfaces or Peak
Protocol. They'll give you *much* more than Java's interfaces.
But even if we disagree about the wisdom of my intentions,
We don't. The point on which we disagree is the proposed solution !-)
do you know
if/when Guido's planning to work that stuff into Python? The last post
I noticed from him on the topic was from 2005. At least back then he
sounded pretty into it.


I don't think this will ever make it into Python. But you really don't
need it anyway. Well, IMHO at least !-)
Jun 22 '06 #5
Christian Convey wrote:
Perhaps I'm deluded but I don't think so. I'll tell you my situation
and I'd appreciate your take on it...

I'm looking into the design a network simulator. The simulator has a
few requirements:

(1) I need to be able to swap in a variety of replacement components
during different simulations. I.e., RadioFrequencyC hannelModel,
WiredNetworkCha nnelModel, etc. This drives me to want the notion of
inherited interfaces, partly as a form of documentation.

(2) I want a form of encapsulation (which I realize isn't necessarily
guaranteed in all possible static typing implementations ). I.e., I want
to ensure that any code which accesses a ChannelModel only calls those
methods that are part of the ChannelModel interface. If there's a
method RadioFrequencyC hannelModel.set BroadcastDistan ce(...), which isn't
part of the generic ChannelModel interface, I don't want most of my code
to be able to start using that particular method, if the code need to be
able to work with all possible ChannelModel implementations .

(3) I like Interfaces as a matter of documentation. It helps me to
thing things through. I've got a lot of components that must support
interchangeable implementations : channels, modems, MAC layers, link
layers, etc. If I have an abstract MAC_layer interface, it helps me
think carefully about what every MAC layer ought to provide, and it also
helps me explain to other people what a MAC layer in my simulator must
provide. That is, it helps me better explain to other people how the
system's major components relate to each other.
All your concerns (and several more) have been beaten to death in past
topics about the benefits and shortcomings of static typing, you can
look them up. Briefly, python doesn't prevent you from writing good
documentation and have nice, clean interfaces if you want to, and
indeed there are several Interface implementations around. Still it
doesn't force you to do so like other "pure" OO languages, which is
very handy if you don't have a crystal clear idea of how your
interfaces should be laid out in advance or if the requirements change
along the way, both very typical scenaria in the real world.

As for encapsulation, again the idea is convention rather than language
enforcement. The convention is to have all non-public elements
(attributes, methods, functions, classes, etc.) starting with a single
underscore. A client can still access it, but he takes the
responsibility of relying on an implementation feature, which is
typically less stable than the public interface.
Now, I could use Java or C# to get functionality such as interfaces, but
I loath giving up the general productive goodness of Python. That's why
I'm looking for something like interfaces.
Others have already mentioned some Interface add-on packages that you
can download and use right away; another option you may want to look
into is the type-checking module
(http://oakwinter.com/code/typecheck/).
But even if we disagree about the wisdom of my intentions, do you know
if/when Guido's planning to work that stuff into Python? The last post
I noticed from him on the topic was from 2005. At least back then he
sounded pretty into it.


I wouldn't count on it if I was to start a project sometime soon.

George

Jun 22 '06 #6
Christian Convey wrote:
Hi guys,

I'm looking at developing a somewhat complex system, and I think some
static typing will help me keep limit my confusion. I.e.:

http://www.artima.com/weblogs/viewpost.jsp?thread=87182

Does anyone know if/when that feature may become part of Python?
Optional static typing is listed as item # 3 in
PEP 3100 (Python 3.0 plans).
For a timeline, look at PEP 3000.

John Roth

Thanks very much,
Christian
--
Christian Convey
Computer Scientist,
Naval Undersea Warfare Centers
Newport, RI
(401) 832-6824
co******@npt.nu wc.navy.mil


Jun 23 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
2576
by: Michael Muller | last post by:
Is there currently any plan to introduce static typing in any future version of Python? (I'm not entirely sure that "static typing" is the right term: what I'm talking about is the declaration of types for variables, parameters and function return values). I know there was a "types SIG" which introduced several proposals, but it expired quite a while ago, and I was wondering whether whether some consensus has been reached on the subject...
15
2678
by: Premshree Pillai | last post by:
How do I force static typing in Python? -Premshree Pillai ===== -Premshree http://www.qiksearch.com/] ________________________________________________________________________ Yahoo! India Insurance Special: Be informed on the best policies, services, tools and more.
8
1826
by: Grzegorz Dostatni | last post by:
I had an idea yesterday. (Yes, I know. Sorry). If we don't need to declare variables as having a certain type, why do we need to import modules into the program? Isn't the "import sys" redundant if all I want is to call "sys.setrecursionlimit(5000)" ? Why couldn't we just try loading the module of a name "sys" to see if it exists and re-try the command? I tried just that. This is meant as a proof of concept (I called it autoload.py)
49
3128
by: bearophileHUGS | last post by:
Adding Optional Static Typing to Python looks like a quite complex thing, but useful too: http://www.artima.com/weblogs/viewpost.jsp?thread=85551 I have just a couple of notes: Boo (http://boo.codehaus.org/) is a different language, but I like its "as" instead of ":" and "->", to have: def min(a as iterable(T)) as T: Instead of:
1
1438
by: Luis M. Gonzalez | last post by:
Hi folks, This is an interesting new article (published today Dec. 23). Guido discusses the possibility of adding optional static typing to Python: http://www.artima.com/weblogs/viewpost.jsp?thread=85551
3
1255
by: John Roth | last post by:
Guido has posted a second blog entry on the optional static typing initiative. I like this a lot better than the first. http://www.artima.com/weblogs/viewpost.jsp?thread=86641 Now, the base objective seems to be to incorporate PyChecker functionality into the root. This in turn requires type inference, which in turn strongly suggests type annotations to help the inferencer out over rough spots.
9
2164
by: Brian Roberts | last post by:
I have a command line Python program that sometimes takes a bit (several minutes) to run. I want to provide an optional method for an impatient user (me!) to check the status of the program. The type and amount of status information doesn't fit nicely into a --verbose or logger -- either too little or too much information at different points. I think an optional web page would be convenient interface. The Python program would listen...
0
9688
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9546
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10491
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10247
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9079
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7571
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5593
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.