Skip to content
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

Examples for episodes 547 & 548 #370

Merged
merged 1 commit into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions sample_code/ep547/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# [shell vs environment variables (and env, export, etc.) (intermediate)](https://youtu.be/h36Xc38SDHg)

Today we talk about environment variables, shell variables, shorthand(s) for setting them and unsetting them!

## Interactive examples

### Python

```python
import os
'X' in os.environ
```

### Bash

```bash
NOSHOW=1 python3 -um scripts.swsh.da --pokemon da-targets --quiet

X=1
echo "$X"

python3

bash -c 'echo $X'
echo $X

export X
bash -c 'echo $X'

export X=2
bash -c 'echo $X'

export -n X
bash -c 'echo $X'

unset X
echo $X

X=1 bash -c 'echo $X'
echo $X

X=1 Y=1 Z= bash -c 'echo $X $Y $Z'

man test

which env

env X=1 bash -c 'echo $X'
env X=1 Y=1 bash -c 'echo $X $Y'

env bash -c 'echo $USER'
env -i bash -c 'echo $USER'
```
124 changes: 124 additions & 0 deletions sample_code/ep548/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# [python 3.12 release highlights (beginner - advanced)](https://youtu.be/IV8OZY4194U)

It's here! with ugly new typing syntax and infinitely nestable fstrings and one of the funniest changes I've seen in a while -- python 3.12!

## Interactive examples

### Python

```python
import calendar
calendar.January
calendar.February
calendar.March

hi = 3
f'hi{f'{hi}'}'

f'hi{
3
}'

f'hi{
3 # hi
}'

Old = int
isinstance(5, Old)

type Newest = int
isinstance(5, Newest)
Newest.__value__

import dis

def f():
x = [i * 2 for i in range(5)]
return x

dis.dis(f)

'\d'
r'\d'
'\\d'

it = [1, 2, 3, 4, 5, 6, 7, 8, 9]

import itertools

for a, b, c in itertools.batched(it, 3):
print(a, b, c)

for a, b in itertools.batched(it, 2):
print(a, b)

sys.version_info

class C:
def __init__(self):
self.x = 1
def f(self):
x

C().f()

import Counter from collections

from collections import counter
```

### Python debugger (pdb)

```
$x = 1
import token
$token = token
$token

y = 1
c
y

q
```

### Bash

```bash
python3.11
python3.12
python3.12 -m pydoc tokenize

cd pre-commit/
best-of -n 5 python3.11 t.py $(git ls-files -- '*.py')
best-of -n 5 python3.12 t.py $(git ls-files -- '*.py')

python3.11 -m tokenize /dev/stdin <<< 'f"hello {world}"'
python3.12 -m tokenize /dev/stdin <<< 'f"hello {world}"'
python3.12 -m tokenize /dev/stdin <<< 'f"{a}({world})"'

python3.12 -m venv vvv
sudo apt install python3.12-venv

virtualenv venv -ppython3.12
./venv/bin/pip freeze --all
./venv/bin/pip install setuptools
./venv/bin/python3 -c 'import distutils'

. venv/bin/activate
pip install pycodestyle
pycodestyle t4.py

pip install pyupgrade
cat t4.py

pyupgrade t4.py
cat t4.py

cd pyflakes
deactivate

python3.12 -m unittest discover pyflakes
python3.12 -m unittest discover pyflakes --duration 5
python3.12 -m unittest discover pyflakes --duration 10
```
14 changes: 14 additions & 0 deletions sample_code/ep548/rev01/t.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import sys
import tokenize


def main() -> int:
for fname in sys.argv[1:]:
with open(fname) as f:
for _ in tokenize.generate_tokens(f.readline):
pass
return 0


if __name__ == '__main__':
raise SystemExit(main())
7 changes: 7 additions & 0 deletions sample_code/ep548/rev02/t.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from typing import TypeVar

T = TypeVar('T')


def f(x: T) -> list[T]:
return [x]
24 changes: 24 additions & 0 deletions sample_code/ep548/rev03/t.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from typing import TypeVar

Z = TypeVar('Z', bound=int)


def f[T: C, U, V](x: T) -> list[T]:
return [x]


async g[T](): ...

class D[T]: pass

class C: pass

Old = int

from typing import TypeAlias

Newer: TypeAlias = "Foo"

type Newest = int

type NewestWithGeneric[T: int] = list[T]
8 changes: 8 additions & 0 deletions sample_code/ep548/rev03/t2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from typing import Any


def f(**kwargs: dict[str, Any]): pass


# not ok f(x=1, y=2)
# ok f(x={}, y={})
12 changes: 12 additions & 0 deletions sample_code/ep548/rev04/t2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from typing import TypedDict, Unpack


class D(TypedDict):
x: int
y: str


def f(**kwargs: Unpack[D]): pass


f(x=1, y='foo')
16 changes: 16 additions & 0 deletions sample_code/ep548/rev04/t3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@


class C:
def frob(self):
print('default')

def do_work(self):
self.frob()


class D(C):
def frob(self):
print('something else')


D().do_work()
18 changes: 18 additions & 0 deletions sample_code/ep548/rev05/t3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from typing import override


class C:
def new_frob(self):
print('default')

def do_work(self):
self.new_frob()


class D(C):
@override
def frob(self):
print('something else')


D().do_work()
1 change: 1 addition & 0 deletions sample_code/ep548/rev05/t4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
x = '\d'
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,5 @@ per-file-ignores =
*/ep439/*/t.py:F821
*/ep496/*/t.py:F401
*/ep546/rev01/t.py:E999
*/ep548/rev03/t.py:E999
*/ep548/rev05/t4.py:W605