Deutsch   English   Français   Italiano  
<test-20241205225548@ram.dialup.fu-berlin.de>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!weretis.net!feeder8.news.weretis.net!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: fr.comp.lang.python
Subject: Re: =?UTF-8?Q?Signature_d'une_fonction_=28was:_[SOLUTION]_Tri_de_cr?= =?UTF-8?B?w6pwZXMp?=
Date: 5 Dec 2024 21:59:24 GMT
Organization: Stefan Ram
Lines: 63
Expires: 1 Jan 2026 11:59:58 GMT
Message-ID: <test-20241205225548@ram.dialup.fu-berlin.de>
References: <vikoqt$3eo5p$1@dont-email.me> <vimqp4$1h59$1@cabale.usenet-fr.net> <vin3d6$1mos$1@cabale.usenet-fr.net> <6750134f$0$12939$426a74cc@news.free.fr> <vipdmh$6ri$1@cabale.usenet-fr.net> <67504685$0$11432$426a34cc@news.free.fr> <viss7a$1crn$1@cabale.usenet-fr.net> <vist0t$1d6j$1@cabale.usenet-fr.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de 8zgUMncMNVwJNtnZXPzZQgnNjrLQxQMHgLg01KVmLU1mMQ
Cancel-Lock: sha1:LHOcymzXggty0FQgO2ptXW5alao= sha256:06/q49n47gMja1s48GkDJUhYodyFRFDcap8s1x/l+t0=
X-Copyright: (C) Copyright 2024 Stefan Ram. All rights reserved.
	Distribution through any means other than regular usenet
	channels is forbidden. It is forbidden to publish this
	article in the Web, to change URIs of this article into links,
        and to transfer the body without this notice, but quotations
        of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
	services to mirror the article in the web. But the article may
	be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: fr
Bytes: 3519

Olivier Miakinen <om+news@miakinen.net> a écrit ou cité :
>Je viens d'essayer en 3.8.10. La syntaxe est accept?e mais ?a ne g?n?re aucune
>erreur si je fais un appel contredisant la signature.
>>>> def test(machin:str, truc:int) -> int:
>...     print(machin, truc)
>...     return machin
>...
>>>> test(3, "7")
>3 7
>3
>>>> test(3, "aed")
>3 aed
>3
>>>> test("def", "aed")
>def aed
>'def'

  Ouais, c'est ouf ! 

  L'idée derrière tout ça, c'est que Python veut rester une
  langue sans typage statique de base. On peut voir les types
  comme des commentaires, ou utiliser des outils supplémentaires
  pour vérifier les types.

  Un exemple, c'est « mypy ». Généralement, on l'appelle comme un
  script externe, mais des fois je le lance directement depuis mon
  script Python. Voici un bout de code avec la sortie : 

  Code source :

from mypy import api; o = api.run([__file__])
if( o[ -1 ]):
    for i in o:
        print( 'mypy:', i )
del api

def test(machin:str, truc:int) -> int:
    print(machin, truc)
    return machin

test(3, "7")

test(3, "aed")

test("def", "aed")

  Sortie :

mypy: test.py:9: error: Incompatible return value type (got "str", expected "int")  [return-value]
test.py:11: error: Argument 1 to "test" has incompatible type "int"; expected "str"  [arg-type]
test.py:11: error: Argument 2 to "test" has incompatible type "str"; expected "int"  [arg-type]
test.py:13: error: Argument 1 to "test" has incompatible type "int"; expected "str"  [arg-type]
test.py:13: error: Argument 2 to "test" has incompatible type "str"; expected "int"  [arg-type]
test.py:15: error: Argument 2 to "test" has incompatible type "str"; expected "int"  [arg-type]
Found 6 errors in 1 file (checked 1 source file)

mypy: 
mypy: 1
3 7
3 aed
def aed