From 13293997540daaa1fcdeb0409432ddfe2e4b5455 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Wed, 18 Dec 2024 06:35:22 +0100 Subject: [PATCH] Iterable duck types, Deque, Introspection --- README.md | 8 ++++---- index.html | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 74a688e..26fd401 100644 --- a/README.md +++ b/README.md @@ -1294,8 +1294,8 @@ class MySequence: ``` #### Discrepancies between glossary definitions and abstract base classes: -* **Python's glossary defines iterable as any object with iter() or getitem() and sequence as any object with getitem() and len(). It does not define collection.** -* **Passing ABC Iterable to isinstance() or issubclass() checks whether object/class has method iter(), while ABC Collection checks for iter(), contains() and len().** +* **Python's glossary defines iterable as any object with special methods iter() and/or getitem() and sequence as any object with getitem() and len(). It doesn't define collection.** +* **Passing ABC Iterable to isinstance() or issubclass() only checks whether object/class has special method iter(), while ABC Collection checks for iter(), contains() and len().** ### ABC Sequence * **It's a richer interface than the basic sequence.** @@ -2086,7 +2086,7 @@ Memory View Deque ----- -**List with efficient appends and pops from either side. Pronounced "deck".** +**List with efficient appends and pops from either side.** ```python from collections import deque @@ -2229,7 +2229,7 @@ CRITICAL:my_module:Running out of disk space. Introspection ------------- ```python - = dir() # List of local names (variables, funcs, classes, modules). + = dir() # Local names of variables, functions, classes and modules. = vars() # Dict of local names and their objects. Also locals(). = globals() # Dict of global names and their objects, e.g. __builtin__. ``` diff --git a/index.html b/index.html index 91a4da5..24faa76 100644 --- a/index.html +++ b/index.html @@ -55,7 +55,7 @@
- +
@@ -1099,8 +1099,8 @@ Hello World!

Discrepancies between glossary definitions and abstract base classes:

    -
  • Python's glossary defines iterable as any object with iter() or getitem() and sequence as any object with getitem() and len(). It does not define collection.
  • -
  • Passing ABC Iterable to isinstance() or issubclass() checks whether object/class has method iter(), while ABC Collection checks for iter(), contains() and len().
  • +
  • Python's glossary defines iterable as any object with special methods iter() and/or getitem() and sequence as any object with getitem() and len(). It doesn't define collection.
  • +
  • Passing ABC Iterable to isinstance() or issubclass() only checks whether object/class has special method iter(), while ABC Collection checks for iter(), contains() and len().
@@ -1714,7 +1714,7 @@ CompletedProcess(args=['bc', 'utf-8') # Treats memoryview as a bytes object. <str> = <mview>.hex() # Returns hex pairs. Accepts `sep=<str>`. -

#Deque

List with efficient appends and pops from either side. Pronounced "deck".

from collections import deque
+

#Deque

List with efficient appends and pops from either side.

from collections import deque
 
@@ -1826,7 +1826,7 @@ CRITICAL:my_module:Running out of disk space. 2023-02-07 23:21:01,430 CRITICAL:my_module:Running out of disk space.
-

#Introspection

<list> = dir()                      # List of local names (variables, funcs, classes, modules).
+

#Introspection

<list> = dir()                      # Local names of variables, functions, classes and modules.
 <dict> = vars()                     # Dict of local names and their objects. Also locals().
 <dict> = globals()                  # Dict of global names and their objects, e.g. __builtin__.
 
@@ -2924,7 +2924,7 @@ $ deactivate # Deactivates the active