Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6abea7b

Browse files
authored
Merge pull request #344 from nifadyev/feature/#74/add-dark-theme-and-alt-support-for-images
#74: Add dark theme and alt support for images Resolves #74 Closes #302 Closes #317
2 parents 93d7fb9 + 578c820 commit 6abea7b

19 files changed

+167
-13
lines changed

‎.gitignore‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,8 @@ irrelevant/.ipynb_checkpoints/
1616
irrelevant/.python-version
1717

1818
.idea/
19+
.vscode/
20+
21+
# Virtual envitonments
22+
venv/
23+
.venv/

‎README.md‎

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
<p align="center"><img src="/images/logo.png#gh-light-mode-only" alt=""><img src="/images/logo-dark.png#gh-dark-mode-only" alt=""></p>
1+
<p align="center">
2+
<picture>
3+
<source media="(prefers-color-scheme: dark)" srcset="/images/logo_dark_theme.svg">
4+
<source media="(prefers-color-scheme: light)" srcset="/images/logo.svg">
5+
<img alt="Shows a wtfpython logo." src="/images/logo.svg">
6+
</picture>
7+
</p>
28
<h1 align="center">What the f*ck Python! 😱</h1>
39
<p align="center">Exploring and understanding Python through surprising snippets.</p>
410

@@ -352,7 +358,14 @@ Makes sense, right?
352358
* All length 0 and length 1 strings are interned.
353359
* Strings are interned at compile time (`'wtf'` will be interned but `''.join(['w', 't', 'f'])` will not be interned)
354360
* Strings that are not composed of ASCII letters, digits or underscores, are not interned. This explains why `'wtf!'` was not interned due to `!`. CPython implementation of this rule can be found [here](https://github.com/python/cpython/blob/3.6/Objects/codeobject.c#L19)
355-
![image](/images/string-intern/string_intern.png)
361+
<p align="center">
362+
<picture>
363+
<source media="(prefers-color-scheme: dark)" srcset="/images/string-intern/string_interning_dark_theme.svg">
364+
<source media="(prefers-color-scheme: light)" srcset="/images/string-intern/string_interning.svg">
365+
<img alt="Shows a string interning process." src="/images/string-intern/string_interning.svg">
366+
</picture>
367+
</p>
368+
356369
+ When `a` and `b` are set to `"wtf!"` in the same line, the Python interpreter creates a new object, then references the second variable at the same time. If you do it on separate lines, it doesn't "know" that there's already `"wtf!"` as an object (because `"wtf!"` is not implicitly interned as per the facts mentioned above). It's a compile-time optimization. This optimization doesn't apply to 3.7.x versions of CPython (check this [issue](https://github.com/satwikkansal/wtfpython/issues/100) for more discussion).
357370
+ A compile unit in an interactive environment like IPython consists of a single statement, whereas it consists of the entire module in case of modules. `a, b = "wtf!", "wtf!"` is single statement, whereas `a = "wtf!"; b = "wtf!"` are two statements in a single line. This explains why the identities are different in `a = "wtf!"; b = "wtf!"`, and also explain why they are same when invoked in `some_file.py`
358371
+ The abrupt change in the output of the fourth snippet is due to a [peephole optimization](https://en.wikipedia.org/wiki/Peephole_optimization) technique known as Constant folding. This means the expression `'a'*20` is replaced by `'aaaaaaaaaaaaaaaaaaaa'` during compilation to save a few clock cycles during runtime. Constant folding only occurs for strings having a length of less than 21. (Why? Imagine the size of `.pyc` file generated as a result of the expression `'a'*10**10`). [Here's](https://github.com/python/cpython/blob/3.6/Python/peephole.c#L288) the implementation source for the same.
@@ -975,11 +988,23 @@ We didn't assign three `"X"`s, did we?
975988
976989
When we initialize `row` variable, this visualization explains what happens in the memory
977990
978-
![image](/images/tic-tac-toe/after_row_initialized.png)
991+
<p align="center">
992+
<picture>
993+
<source media="(prefers-color-scheme: dark)" srcset="/images/tic-tac-toe/after_row_initialized_dark_theme.svg">
994+
<source media="(prefers-color-scheme: light)" srcset="/images/tic-tac-toe/after_row_initialized.svg">
995+
<img alt="Shows a memory segment after row is initialized." src="/images/tic-tac-toe/after_row_initialized.svg">
996+
</picture>
997+
</p>
979998
980999
And when the `board` is initialized by multiplying the `row`, this is what happens inside the memory (each of the elements `board[0]`, `board[1]` and `board[2]` is a reference to the same list referred by `row`)
9811000
982-
![image](/images/tic-tac-toe/after_board_initialized.png)
1001+
<p align="center">
1002+
<picture>
1003+
<source media="(prefers-color-scheme: dark)" srcset="/images/tic-tac-toe/after_board_initialized_dark_theme.svg">
1004+
<source media="(prefers-color-scheme: light)" srcset="/images/tic-tac-toe/after_board_initialized.svg">
1005+
<img alt="Shows a memory segment after board is initialized." src="/images/tic-tac-toe/after_board_initialized.svg">
1006+
</picture>
1007+
</p>
9831008
9841009
We can avoid this scenario here by not using `row` variable to generate `board`. (Asked in [this](https://github.com/satwikkansal/wtfpython/issues/68) issue).
9851010
-113 KB
Binary file not shown.

‎images/logo-dark.png‎

-12.7 KB
Binary file not shown.

‎images/logo.png‎

-8.12 KB
Binary file not shown.

0 commit comments

Comments
 (0)