Skip to content

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

Merged
merged 2 commits into from
Oct 12, 2019

Conversation

hoefling
Copy link
Contributor

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.

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
Copy link
Contributor Author

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?

Copy link
Member

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
Copy link
Contributor Author

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.

Copy link
Member

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
Copy link
Contributor Author

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.

Copy link
Member

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>`
Copy link
Contributor Author

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.
Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Member

@gvanrossum gvanrossum left a 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.

@@ -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``:
Copy link
Member

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.

Copy link
Contributor Author

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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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.

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
Copy link
Member

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.

Copy link
Contributor Author

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``.
Copy link
Member

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.

Copy link
Contributor Author

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.
Copy link
Member

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>
@gvanrossum gvanrossum merged commit 0e41cce into python:master Oct 12, 2019
@hoefling hoefling deleted the stdlib-crossref-5 branch October 13, 2019 07:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy