Skip to content

Commit 10a8511

Browse files
updated packaes and removed test cell
1 parent 1d5a8b5 commit 10a8511

47 files changed

Lines changed: 880 additions & 502 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/CODE_OF_CONDUCT.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,11 @@ <h1 class="site-logo" id="site-title">Prodigious Python 🐍</h1>
307307
29. Class Attributes
308308
</a>
309309
</li>
310+
<li class="toctree-l1">
311+
<a class="reference internal" href="prodigiouspython/Chapter_8/3_Class_Static_Methods.html">
312+
30. ClassMethod and StaticMethod
313+
</a>
314+
</li>
310315
</ul>
311316

312317
</div>

docs/README.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,11 @@ <h1 class="site-logo" id="site-title">Prodigious Python 🐍</h1>
307307
29. Class Attributes
308308
</a>
309309
</li>
310+
<li class="toctree-l1">
311+
<a class="reference internal" href="prodigiouspython/Chapter_8/3_Class_Static_Methods.html">
312+
30. ClassMethod and StaticMethod
313+
</a>
314+
</li>
310315
</ul>
311316

312317
</div>

docs/_sources/prodigiouspython/Chapter_1/4_Datatypes.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@
527527
"name": "python",
528528
"nbconvert_exporter": "python",
529529
"pygments_lexer": "ipython3",
530-
"version": "3.9.5"
530+
"version": "3.9.7"
531531
}
532532
},
533533
"nbformat": 4,

docs/_sources/prodigiouspython/Chapter_8/2_Class_Attributes.ipynb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -618,14 +618,6 @@
618618
"There's no advantage of using class attributes if there are chances of altering only for a particular instance using `self`, so hard rule is use `<Class>.<class_attribute>` for accessing the class within the class 😤.\n",
619619
"```"
620620
]
621-
},
622-
{
623-
"cell_type": "markdown",
624-
"id": "91b718e9-62c1-4b2c-801a-68d92d0c28ce",
625-
"metadata": {},
626-
"source": [
627-
"## This is a test"
628-
]
629621
}
630622
],
631623
"metadata": {

docs/_sources/prodigiouspython/Chapter_8/3_Class_Static_Methods.ipynb

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,87 @@
3737
"id": "bb4f57d7-b874-427f-a976-2b32375ee4bd",
3838
"metadata": {},
3939
"source": [
40-
"The Static methods are created using the decorator `staticmethod`. "
40+
"The Static methods are created using the decorator `staticmethod`."
4141
]
4242
},
4343
{
4444
"cell_type": "code",
4545
"execution_count": null,
4646
"id": "e785758b-8ef9-4920-9fdf-5d0f0d9d8976",
47-
"metadata": {},
47+
"metadata": {
48+
"tags": []
49+
},
4850
"outputs": [],
4951
"source": [
5052
"class StaticMethodExample:\n",
5153
" @staticmethod\n",
5254
" def do_something():\n",
5355
" "
5456
]
57+
},
58+
{
59+
"cell_type": "code",
60+
"execution_count": 1,
61+
"id": "87f2b054-fbab-4bdb-b01c-ef66d5bdb869",
62+
"metadata": {},
63+
"outputs": [],
64+
"source": [
65+
"class Anime:\n",
66+
" list_of_animes = []\n",
67+
" \n",
68+
" def __init__(self, name, characters):\n",
69+
" self.name = name\n",
70+
" self.characters = characters\n",
71+
" Anime.list_of_animes.append(name)\n",
72+
" \n",
73+
" def introduce(self): # Instance Method.\n",
74+
" print(f\"Hey weebs! We are {self.name}. We have awesome characters: {self.characters} 🔥\")\n",
75+
" \n",
76+
" @classmethod \n",
77+
" def show_list_and_count_of_animes(cls): # Class Method.\n",
78+
" print(f\"Animes listed are: {cls.list_of_animes} which sums up to {len(cls.list_of_animes)}\")\n",
79+
" \n",
80+
" @staticmethod\n",
81+
" def temp():\n",
82+
" return Anime.list_of_animes, __class__.list_of_animes\n",
83+
" \n",
84+
" \n",
85+
" \n",
86+
" "
87+
]
88+
},
89+
{
90+
"cell_type": "code",
91+
"execution_count": 3,
92+
"id": "2bed91ec-a06a-4918-b224-7b65f41f4121",
93+
"metadata": {},
94+
"outputs": [],
95+
"source": [
96+
"a = Anime(\"one piece\", (\"luffy\",))\n",
97+
"b = Anime(\"naruto\", (\"naruto\", ))"
98+
]
99+
},
100+
{
101+
"cell_type": "markdown",
102+
"id": "191cc8fb-0708-497c-b76d-d1e3d52118b1",
103+
"metadata": {},
104+
"source": [
105+
"| Method type | Can modify Class Attribute? | Can modify Method Attribute?|\n",
106+
"|----------------------|-------------------------------|-----------------------------|\n",
107+
"| Instance Method | ✅ | ✅ |\n",
108+
"| Class Method | ✅ | ❌ |\n",
109+
"| Static Method | ❌ | ❌ |"
110+
]
111+
},
112+
{
113+
"cell_type": "markdown",
114+
"id": "a14d5dd8-438f-44b5-929c-9f6391c67ae3",
115+
"metadata": {},
116+
"source": [
117+
"```{note}\n",
118+
"Don't curse me saying, Hey! I can still modify class attributes from Static Method. Yes, we can absolutely do it using the class as `<ClassName>.<class_attribute>`, but we wouldn't be having class \n",
119+
"```"
120+
]
55121
}
56122
],
57123
"metadata": {

docs/_static/doctools.js

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,7 @@ var Documentation = {
154154
this.fixFirefoxAnchorBug();
155155
this.highlightSearchWords();
156156
this.initIndexTable();
157-
if (DOCUMENTATION_OPTIONS.NAVIGATION_WITH_KEYS) {
158-
this.initOnKeyListeners();
159-
}
157+
this.initOnKeyListeners();
160158
},
161159

162160
/**
@@ -269,6 +267,13 @@ var Documentation = {
269267
window.history.replaceState({}, '', url);
270268
},
271269

270+
/**
271+
* helper function to focus on search bar
272+
*/
273+
focusSearchBar : function() {
274+
$('input[name=q]').first().focus();
275+
},
276+
272277
/**
273278
* make the url absolute
274279
*/
@@ -291,27 +296,54 @@ var Documentation = {
291296
},
292297

293298
initOnKeyListeners: function() {
299+
// only install a listener if it is really needed
300+
if (!DOCUMENTATION_OPTIONS.NAVIGATION_WITH_KEYS &&
301+
!DOCUMENTATION_OPTIONS.ENABLE_SEARCH_SHORTCUTS)
302+
return;
303+
294304
$(document).keydown(function(event) {
295305
var activeElementType = document.activeElement.tagName;
296306
// don't navigate when in search box, textarea, dropdown or button
297307
if (activeElementType !== 'TEXTAREA' && activeElementType !== 'INPUT' && activeElementType !== 'SELECT'
298-
&& activeElementType !== 'BUTTON' && !event.altKey && !event.ctrlKey && !event.metaKey
299-
&& !event.shiftKey) {
300-
switch (event.keyCode) {
301-
case 37: // left
302-
var prevHref = $('link[rel="prev"]').prop('href');
303-
if (prevHref) {
304-
window.location.href = prevHref;
305-
return false;
306-
}
307-
break;
308-
case 39: // right
309-
var nextHref = $('link[rel="next"]').prop('href');
310-
if (nextHref) {
311-
window.location.href = nextHref;
312-
return false;
313-
}
314-
break;
308+
&& activeElementType !== 'BUTTON') {
309+
if (event.altKey || event.ctrlKey || event.metaKey)
310+
return;
311+
312+
if (!event.shiftKey) {
313+
switch (event.key) {
314+
case 'ArrowLeft':
315+
if (!DOCUMENTATION_OPTIONS.NAVIGATION_WITH_KEYS)
316+
break;
317+
var prevHref = $('link[rel="prev"]').prop('href');
318+
if (prevHref) {
319+
window.location.href = prevHref;
320+
return false;
321+
}
322+
break;
323+
case 'ArrowRight':
324+
if (!DOCUMENTATION_OPTIONS.NAVIGATION_WITH_KEYS)
325+
break;
326+
var nextHref = $('link[rel="next"]').prop('href');
327+
if (nextHref) {
328+
window.location.href = nextHref;
329+
return false;
330+
}
331+
break;
332+
case 'Escape':
333+
if (!DOCUMENTATION_OPTIONS.ENABLE_SEARCH_SHORTCUTS)
334+
break;
335+
Documentation.hideSearchWords();
336+
return false;
337+
}
338+
}
339+
340+
// some keyboard layouts may need Shift to get /
341+
switch (event.key) {
342+
case '/':
343+
if (!DOCUMENTATION_OPTIONS.ENABLE_SEARCH_SHORTCUTS)
344+
break;
345+
Documentation.focusSearchBar();
346+
return false;
315347
}
316348
}
317349
});

docs/_static/documentation_options.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@ var DOCUMENTATION_OPTIONS = {
88
LINK_SUFFIX: '.html',
99
HAS_SOURCE: true,
1010
SOURCELINK_SUFFIX: '',
11-
NAVIGATION_WITH_KEYS: true
11+
NAVIGATION_WITH_KEYS: true,
12+
SHOW_SEARCH_SUMMARY: true,
13+
ENABLE_SEARCH_SHORTCUTS: true,
1214
};

docs/_static/searchtools.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,6 @@ var Search = {
172172
}
173173
// stem the word
174174
var word = stemmer.stemWord(tmp[i].toLowerCase());
175-
// prevent stemmer from cutting word smaller than two chars
176-
if(word.length < 3 && tmp[i].length >= 3) {
177-
word = tmp[i];
178-
}
179175
var toAppend;
180176
// select the correct list
181177
if (word[0] == '-') {
@@ -276,7 +272,7 @@ var Search = {
276272
setTimeout(function() {
277273
displayNextItem();
278274
}, 5);
279-
} else if (DOCUMENTATION_OPTIONS.HAS_SOURCE) {
275+
} else if (DOCUMENTATION_OPTIONS.SHOW_SEARCH_SUMMARY) {
280276
$.ajax({url: requestUrl,
281277
dataType: "text",
282278
complete: function(jqxhr, textstatus) {
@@ -293,7 +289,7 @@ var Search = {
293289
}, 5);
294290
}});
295291
} else {
296-
// no source available, just display title
292+
// just display title
297293
Search.output.append(listItem);
298294
setTimeout(function() {
299295
displayNextItem();

docs/_static/togglebutton.css

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,25 @@ button.toggle-button {
6464
stroke: currentColor; /* So that we inherit the color of other text */
6565
}
6666

67-
details.toggle-details .tb-icon {
68-
height: 1.3em;
69-
width: 1.3em;
67+
/* Rotate icon with admonitions so that it points down */
68+
.admonition.toggle .tb-icon {
69+
transform: rotate(-90deg);
7070
}
7171

72-
.toggle-button-hidden .tb-icon {
73-
transform: rotate(90deg);
72+
/* When the admonition is hidden, icon should flip upwards but retain rotation */
73+
/* We scaleX, in order to flip along Y, because it is rotated */
74+
.admonition.toggle .toggle-button-hidden .tb-icon {
75+
transform: rotate(-90deg) scaleX(-1);
76+
}
77+
78+
/* With details toggles, we don't rotate the icon so it points right */
79+
details.toggle-details .tb-icon {
80+
height: 1.4em;
81+
width: 1.4em;
82+
margin-top: 0.1em; /* To center the button vertically */
7483
}
7584

85+
7686
/**
7787
* Details-based toggles.
7888
* In this case, we wrap elements with `.toggle` in a details block.
@@ -92,8 +102,12 @@ details.toggle-details summary {
92102
border-radius: .4em;
93103
border: 1px solid #ccc;
94104
background: #f8f8f8;
95-
padding: 0.4em 1em 0.4em 0.5em; /* Less padding on left because the SVG has left margin */
96-
font-size: .9em;
105+
padding: 0.2em 0.7em 0.3em 0.5em; /* Less padding on left because the SVG has left margin */
106+
font-size: 0.8em;
107+
}
108+
109+
.toggle-details__summary-text {
110+
margin-left: 0.2em;
97111
}
98112

99113
details.toggle-details summary:hover {

docs/_static/togglebutton.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var initToggleItems = () => {
2525
}
2626
// This is the button that will be added to each item to trigger the toggle
2727
var collapseButton = `
28-
<button type="button" id="${buttonID}" class="toggle-button" data-target="${toggleID}" data-button="${buttonID}", data-toggle-hint="${toggleHintShow}">
28+
<button type="button" id="${buttonID}" class="toggle-button" data-target="${toggleID}" data-button="${buttonID}" data-toggle-hint="${toggleHintShow}" aria-label="Click to toggle content">
2929
${toggleChevron}
3030
</button>`;
3131

@@ -50,9 +50,9 @@ var initToggleItems = () => {
5050
// Define the structure of the details block and insert it as a sibling
5151
var detailsBlock = `
5252
<details class="toggle-details">
53-
<summary>
53+
<summary class="toggle-details__summary">
5454
${toggleChevron}
55-
<span>${toggleHintShow}</span>
55+
<span class="toggle-details__summary-text">${toggleHintShow}</span>
5656
</summary>
5757
</details>`;
5858
item.insertAdjacentHTML("beforebegin", detailsBlock);

0 commit comments

Comments
 (0)