On Wed, Jul 10, 2019 at 6:11 AM Shay Cohen <sha...@gmail.com> wrote:
>
>
> >>> a: 3
> >>> type(a: 3)
>   File "<stdin>", line 1
>     type(a: 3)
>           ^
> SyntaxError: invalid syntax
> >>> a: 3
> >>> type(a)
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> NameError: name 'a' is not defined
> >>> a
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> NameError: name 'a' is not defined

This kind of question is better asked on the main python-list, as this
one is about making suggestions for future changes.

What you've done there is create a type annotation (albeit a
meaningless one). On its own, that's not very useful, but there are
many great ways to use them:

@dataclass
class PackedItemData(ProtoBuf):
    serial: bytes
    quantity: int
    equipped: int
    mark: int

These annotations define the way that this structure is loaded and
saved in a file, but they don't actually give values to those
variables (which is why you still get the NameError). There's just a
record in the annotations dictionary saying "hey, mark is meant to be
an int", or in your case, "hey, a is meant to be a 3".

ChrisA
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/WEFN3XGL5YZLQQPIQYQD6W2FPP7P6LNN/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to