Comments (9)
This is one of my least favorite parts of the draft. I haven't had time to
come up with something better, but the dictionary notation is too verbose
to my taste. I'm not sure that your TaggedType proposal is any less verbose
though.
On Thu, Nov 6, 2014 at 4:45 PM, Michael Vitousek [email protected]
wrote:
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):def notify_by_email(employees: {'type': List[Employee], 'min_size': 1, 'max_size': 100}): ...
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 a TaggedType
or similar class, which cleanly separates type information from other
information that the programmer wants in their annotations:def notify_by_email(employees: TaggedType(List[Employee], {'min_size': 1, 'max_size': 100}): ...
or
def notify_by_email(employees: TaggedType(List[Employee], 'list of employees to be notified')): ...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 #11).—
Reply to this email directly or view it on GitHub
#26.
--Guido van Rossum (python.org/~guido)
from typing.
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.
from typing.
The decorator idea to turn off the checker is a good one.
from typing.
Let's do a decorator in typing.py to silence the static checker. It should
work for classes and functions/methods.
Let's not do a decorator to add annotations (I think the use cases would be
too uncommon).
Proposal for the name: @no_type_check or @skip_type_check.
On Wed, Jan 7, 2015 at 12:11 AM, Łukasz Langa [email protected]
wrote:
The decorator idea to turn off the checker is a good one.
—
Reply to this email directly or view it on GitHub
#26 (comment).
--Guido van Rossum (python.org/~guido)
from typing.
@gvanrossum, agreed with just adding the silencing decorator.
Bike shedding for a second, you decide. Skip underscores maybe?
- @classmethod, @staticmethod, @contextmanager, lots of single word ones like @asyncio.coroutine.
- Counter examples: @lru_cache, @total_ordering, etc.
from typing.
Let's do @no_type_checks
. (Or, more verbose, @typing.no_type_checks
.)
We may still have a comment too (I'm undecided on that, but comments are not ruled out).
from typing.
Fixed in e2e6fc4 (comment named as "type: ignore" for now).
from typing.
Added mypy issue: python/mypy#557
from typing.
Update: it should be @no_type_check
and @no_type_check_decorator
as was chosen for the PEP and in some other discussion (can't find the issue right now).
from typing.
Related Issues (20)
- how do I pass down the Class type to a method without using it as a parameter HOT 1
- Spec: Specify how inheriting from Any works HOT 2
- Specify what happens for binary operators (e.g. `__add__`) HOT 3
- Specify NamedTuple HOT 2
- Allow unary `+` in integer Literals HOT 1
- Pass variable as final HOT 4
- Spec: Allow `NoReturn` to appear outside of function return type annotations HOT 6
- Treat alternative syntax for unions (and other "new-semantics-old-syntax" typing features) in explicit `TypeAlias`es inside `if TYPE_CHECKING` blocks as stringized annotations. HOT 6
- Spec: Annotating the `self` argument in `__init__` methods HOT 17
- FYI: I removed the "stable" docs version
- Pre-draft proposal: Amend the prior removal of support for unpacking of typevartuples in union. (revisiting pep 646) HOT 1
- PR preview HOT 3
- Outdated stub package guidance HOT 1
- Integrate the Type Stubs document into the spec HOT 1
- Types for "truthy" and "falsy" values HOT 6
- Abstract classmethod returning object of type cls: "is not a supertype of its class" HOT 1
- hello
- Spec: Add PEP 696 (Type parameter defaults) HOT 2
- Spec: Add PEP 705 (Read-only TypedDict items) HOT 3
- Extra key of TypedDict HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typing.