-
Notifications
You must be signed in to change notification settings - Fork 237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Other uses of annotations #26
Comments
This is one of my least favorite parts of the draft. I haven't had time to On Thu, Nov 6, 2014 at 4:45 PM, Michael Vitousek notifications@github.com
--Guido van Rossum (python.org/~guido) |
I don't like this much. I think having function or file level granularity would probably be sufficient. Perhaps use a function decorator for escaping out of type annotations (somebody suggested this already). Here is the first thing than came to mind: from typing import ignore_annotation as mydecorator
@mydecorator
def f(x: ('my', 'own', 'annotation')) -> 'not a type':
... If we have a fallback approach for annotating Python 2 code in a way that makes the types available for introspection, we could use this to have multiple annotations. For example (similar to the proposal by Andrey Vlasovskikh -- https://github.com/JukkaL/typing/issues/12): from typing import annotations, ignore_annotation
@annotations(x=int, returns=str)
@ignore_annotation
def f(x: 'my annotation') -> 'totally non-standard':
print(x + 'x') # type error This is still not great, IMHO, but I think that it's less bad than the alternatives that have been proposed. |
The decorator idea to turn off the checker is a good one. |
Let's do a decorator in typing.py to silence the static checker. It should Let's not do a decorator to add annotations (I think the use cases would be Proposal for the name: @no_type_check or @skip_type_check. On Wed, Jan 7, 2015 at 12:11 AM, Łukasz Langa notifications@github.com
--Guido van Rossum (python.org/~guido) |
@gvanrossum, agreed with just adding the silencing decorator. Bike shedding for a second, you decide. Skip underscores maybe?
|
Let's do We may still have a comment too (I'm undecided on that, but comments are not ruled out). |
Fixed in e2e6fc4 (comment named as "type: ignore" for now). |
Added mypy issue: python/mypy#557 |
Update: it should be |
Currently the proposal suggests a dictionary-based syntax for allowing the arbitrary annotations currently used in Python 3 to coexist with type annotations (https://github.com/ambv/typehinting/blob/master/pep-NNNN.txt#L194):
This meshes well with existing usage if the existing non-type annotation is already a dictionary, but if it's some other kind of value it forces additional refactoring. Maybe instead,
typing
could provide aTaggedType
or similar class, which cleanly separates type information from other information that the programmer wants in their annotations:The first argument is always a type, and the second argument is any arbitrary value.
This would also free up dictionaries for possibly representing structural types/protocols (see #11).
The text was updated successfully, but these errors were encountered: