-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Crossreferences to standard library in mypy docs, part 5 #7689
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
Conversation
Signed-off-by: Oleg Höfling <oleg.hoefling@gmail.com>
@@ -415,7 +415,7 @@ Disabling strict optional checking | |||
Mypy also has an option to treat ``None`` as a valid value for every | |||
type (in case you know Java, it's useful to think of it as similar to | |||
the Java ``null``). In this mode ``None`` is also valid for primitive | |||
types such as ``int`` and ``float``, and ``Optional[...]`` types are | |||
types such as ``int`` and ``float``, and :py:data:`~typing.Optional` types are |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it a similar case to this one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. (No need to link int
, float
since they are well-known.)
@@ -600,10 +600,10 @@ The type of class objects | |||
<484#the-type-of-class-objects>`.) | |||
|
|||
Sometimes you want to talk about class objects that inherit from a | |||
given class. This can be spelled as ``Type[C]`` where ``C`` is a | |||
given class. This can be spelled as :py:class:`Type[C] <typing.Type>` where ``C`` is a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please advise whether the reference is useful here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty marginal, since this section explains the meaning of Type[]
. But I think it's still fine to link to it.
@@ -634,7 +634,7 @@ you pass it the right class object: | |||
# (Here we could write the user object to a database) | |||
return user | |||
|
|||
How would we annotate this function? Without ``Type[]`` the best we | |||
How would we annotate this function? Without :py:class:`~typing.Type` the best we |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it wise to remove the brackets here? TBH I didn't understand their meaning here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's fine. The meaning is similar to the use of ()
after a name (e.g. foo()
) to emphasize that it's a function. (The latter usage goes back to the oldest UNIX manuals and/or K&R's original C book.) But it's not ambiguous in this context, so they can go.
@@ -32,7 +32,7 @@ In Python 2, the syntax for defining a metaclass is different: | |||
class A(object): | |||
__metaclass__ = M | |||
|
|||
Mypy also supports using :py:func:`six.with_metaclass` | |||
Mypy also supports using :py:func:`six.with_metaclass` and :py:func:`@six.add_metaclass <six.add_metaclass>` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have decided to extend the text as the @six.add_metaclass
decorator is used in the subsequent code example as well.
@@ -15,7 +15,7 @@ Run mypy in Python 2 mode by using the ``--py2`` option:: | |||
To run your program, you must have the ``typing`` module in your | |||
Python 2 module search path. Use ``pip install typing`` to install the | |||
module. This also works for Python 3 versions prior to 3.5 that don't | |||
include ``typing`` in the standard library. | |||
include :py:mod:`typing` in the standard library. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe not add any references in this document at all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, this one reference seems fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1-2 nits need action.
docs/source/kinds_of_types.rst
Outdated
@@ -108,7 +108,7 @@ The ``Any`` type is discussed in more detail in section :ref:`dynamic-typing`. | |||
Tuple types | |||
*********** | |||
|
|||
The type ``Tuple[T1, ..., Tn]`` represents a tuple with the item types ``T1``, ..., ``Tn``: | |||
The type ``Tuple[T1, ..., Tn]`` represents a :py:data:`~typing.Tuple` with the item types ``T1``, ..., ``Tn``: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is wrong -- "tuple" here references the builtin tuple
type, or the informal "tuple" concept, but making it reference typing.Tuple
seems tautological.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed - now it sounds like "the Tuple
type represents itself", which is nonsensical. I guess my desire to reference the typing.Tuple
type here and not touch Tuple[T1, ..., Tn]
simultaneously played a bad joke on me. Will revert!
@@ -415,7 +415,7 @@ Disabling strict optional checking | |||
Mypy also has an option to treat ``None`` as a valid value for every | |||
type (in case you know Java, it's useful to think of it as similar to | |||
the Java ``null``). In this mode ``None`` is also valid for primitive | |||
types such as ``int`` and ``float``, and ``Optional[...]`` types are | |||
types such as ``int`` and ``float``, and :py:data:`~typing.Optional` types are |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. (No need to link int
, float
since they are well-known.)
@@ -600,10 +600,10 @@ The type of class objects | |||
<484#the-type-of-class-objects>`.) | |||
|
|||
Sometimes you want to talk about class objects that inherit from a | |||
given class. This can be spelled as ``Type[C]`` where ``C`` is a | |||
given class. This can be spelled as :py:class:`Type[C] <typing.Type>` where ``C`` is a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty marginal, since this section explains the meaning of Type[]
. But I think it's still fine to link to it.
@@ -634,7 +634,7 @@ you pass it the right class object: | |||
# (Here we could write the user object to a database) | |||
return user | |||
|
|||
How would we annotate this function? Without ``Type[]`` the best we | |||
How would we annotate this function? Without :py:class:`~typing.Type` the best we |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's fine. The meaning is similar to the use of ()
after a name (e.g. foo()
) to emphasize that it's a function. (The latter usage goes back to the oldest UNIX manuals and/or K&R's original C book.) But it's not ambiguous in this context, so they can go.
docs/source/kinds_of_types.rst
Outdated
object that's a subtype of ``C``. Its constructor must be | ||
compatible with the constructor of ``C``. If ``C`` is a type | ||
variable, its upper bound must be a class object. | ||
|
||
For more details about ``Type[]`` see :pep:`PEP 484: The type of | ||
For more details about :py:class:`~typing.Type` see :pep:`PEP 484: The type of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is kind of funny since there are now two references in the sentence, to different "sources of truth". I'll defer to your own sense of style in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed - I would rather revert to PEP 484 as the typing.Type
docs are too brief.
|
||
Mypy has some special understanding of ``ABCMeta`` and ``EnumMeta``. | ||
Mypy has some special understanding of :py:class:`~abc.ABCMeta` and ``EnumMeta``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Too bad there's no formal docs for EnumMeta
, but I guess we can't do anything about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, unfortunately! The only reference to EnumMeta
I found in the stdlib docs is a brief mentioning in Enum Classes. No reference to link to in PEP 435 either.
@@ -15,7 +15,7 @@ Run mypy in Python 2 mode by using the ``--py2`` option:: | |||
To run your program, you must have the ``typing`` module in your | |||
Python 2 module search path. Use ``pip install typing`` to install the | |||
module. This also works for Python 3 versions prior to 3.5 that don't | |||
include ``typing`` in the standard library. | |||
include :py:mod:`typing` in the standard library. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, this one reference seems fine.
Signed-off-by: Oleg Höfling <oleg.hoefling@gmail.com>
Added references to the following documents:
kinds_of_types.rst
metaclasses.rst
python2.rst
python36.rst
running_mypy.rst
stubs.rst
supported_python_features.rst
type_inference_and_annotations.rst
This is part of splitting up the changes in #7624 into more readable PRs.