| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -44,7 +44,8 @@ Any object can be tested for truth value, for use in an :keyword:`if` or | |
| .. index:: single: true | ||
|
|
||
| By default, an object is considered true unless its class defines either a | ||
| :meth:`~object.__bool__` method that returns ``False`` or a :meth:`__len__` method that | ||
| :meth:`~object.__bool__` method that returns ``False`` or a | ||
| :meth:`~object.__len__` method that | ||
| returns zero, when called with the object. [1]_ Here are most of the built-in | ||
| objects considered false: | ||
|
|
||
| Expand Down Expand Up | @@ -197,7 +198,7 @@ exception. | |
|
|
||
| Two more operations with the same syntactic priority, :keyword:`in` and | ||
| :keyword:`not in`, are supported by types that are :term:`iterable` or | ||
| implement the :meth:`__contains__` method. | ||
| implement the :meth:`~object.__contains__` method. | ||
|
|
||
| .. _typesnumeric: | ||
|
|
||
| Expand Down Expand Up | @@ -717,7 +718,7 @@ that's defined for any rational number, and hence applies to all instances of | |
| :class:`int` and :class:`fractions.Fraction`, and all finite instances of | ||
| :class:`float` and :class:`decimal.Decimal`. Essentially, this function is | ||
| given by reduction modulo ``P`` for a fixed prime ``P``. The value of ``P`` is | ||
| made available to Python as the :attr:`modulus` attribute of | ||
| made available to Python as the :attr:`~sys.hash_info.modulus` attribute of | ||
| :data:`sys.hash_info`. | ||
|
|
||
| .. impl-detail:: | ||
| Expand Down Expand Up | @@ -906,9 +907,9 @@ Generator Types | |
| --------------- | ||
|
|
||
| Python's :term:`generator`\s provide a convenient way to implement the iterator | ||
| protocol. If a container object's :meth:`__iter__` method is implemented as a | ||
| protocol. If a container object's :meth:`~iterator.__iter__` method is implemented as a | ||
| generator, it will automatically return an iterator object (technically, a | ||
| generator object) supplying the :meth:`__iter__` and :meth:`~generator.__next__` | ||
| generator object) supplying the :meth:`!__iter__` and :meth:`~generator.__next__` | ||
| methods. | ||
| More information about generators can be found in :ref:`the documentation for | ||
| the yield expression <yieldexpr>`. | ||
| Expand Down Expand Up | @@ -3672,7 +3673,7 @@ The conversion types are: | |
| +------------+-----------------------------------------------------+-------+ | ||
| | ``'b'`` | Bytes (any object that follows the | \(5) | | ||
| | | :ref:`buffer protocol <bufferobjects>` or has | | | ||
| | | :meth:`__bytes__`). | | | ||
| | | :meth:`~object.__bytes__`). | | | ||
| +------------+-----------------------------------------------------+-------+ | ||
| | ``'s'`` | ``'s'`` is an alias for ``'b'`` and should only | \(6) | | ||
| | | be used for Python2/3 code bases. | | | ||
| Expand Down Expand Up | @@ -4410,7 +4411,8 @@ The constructors for both classes work the same: | |
| :meth:`symmetric_difference_update` methods will accept any iterable as an | ||
| argument. | ||
|
|
||
| Note, the *elem* argument to the :meth:`__contains__`, :meth:`remove`, and | ||
| Note, the *elem* argument to the :meth:`~object.__contains__`, | ||
| :meth:`remove`, and | ||
| :meth:`discard` methods may be a set. To support searching for an equivalent | ||
| frozenset, a temporary one is created from *elem*. | ||
|
|
||
| Expand Down Expand Up | @@ -5236,9 +5238,11 @@ instantiated from the type:: | |
| TypeError: cannot create 'types.UnionType' instances | ||
|
|
||
| .. note:: | ||
| The :meth:`__or__` method for type objects was added to support the syntax | ||
| ``X | Y``. If a metaclass implements :meth:`__or__`, the Union may | ||
| override it:: | ||
| The :meth:`!__or__` method for type objects was added to support the syntax | ||
| ``X | Y``. If a metaclass implements :meth:`!__or__`, the Union may | ||
|
Comment thread
Comment on lines
+5241
to
+5242
Copy link
Copy Markdown
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityI considered linking to https://docs.python.org/3/reference/datamodel.html#object.__or__, but the data model only discusses implementing __or__ in the context of emulating numeric types, and that's pretty distinct to the purpose of type.__or__
Sorry, something went wrong.
All reactions
|
||
| override it: | ||
|
|
||
| .. doctest:: | ||
|
|
||
| >>> class M(type): | ||
| ... def __or__(self, other): | ||
| Expand All | @@ -5250,7 +5254,7 @@ instantiated from the type:: | |
| >>> C | int | ||
| 'Hello' | ||
| >>> int | C | ||
| int | __main__.C | ||
| int | C | ||
|
|
||
| .. seealso:: | ||
|
|
||
| Expand Down | ||
| Back | FazBrowse Home | New Git URL |
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.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityIt can refer to io.BaseIO.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityI'm not sure there's anything we could specifically link to for either method. io.IOBase does not have read() or write() as abstract methods, so neither IOBase.read nor IOBase.write is explicitly documented currently.
https://docs.python.org/3/library/io.html#io.IOBase
Here's all the IOBase docs say on read and write:
Specific subclasses of IOBase implement versions of read and write that either only work with raw binary streams or only work with text streams
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityWell, and there is a reason to not declare them there. But there are many other references to read and write. It would be nice to have the general interface of them be documented somewhere. It is a different issue.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.