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

#350: Add Nox and basic pyproject.toml created by Poetry #353

Merged
merged 2 commits into from
Nov 5, 2024
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
56 changes: 20 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,53 +289,37 @@ This saved one line of code, and implicitly prevented invoking `some_func` twice
### ▶ Strings can be tricky sometimes

<!-- Example ID: 30f1d3fc-e267-4b30-84ef-4d9e7091ac1a --->
1\.

```py
>>> a = "some_string"
>>> id(a)
140420665652016
>>> id("some" + "_" + "string") # Notice that both the ids are same.
140420665652016
```

2\.

```py
>>> a = "wtf"
>>> b = "wtf"
>>> a is b
True

>>> a = "wtf!"
>>> b = "wtf!"
>>> a is b
False
1\. Notice that both the ids are same.

```python:snippets/2_tricky_strings.py -s 2 -e 3
assert id("some_string") == id("some" + "_" + "string")
assert id("some_string") == id("some_string")
```

3\.
2\. `True` because it is invoked in script. Might be `False` in `python shell` or `ipython`

```py
>>> a, b = "wtf!", "wtf!"
>>> a is b # All versions except 3.7.x
True
```python:snippets/2_tricky_strings.py -s 6 -e 12
satwikkansal marked this conversation as resolved.
Show resolved Hide resolved
a = "wtf"
b = "wtf"
assert a is b

>>> a = "wtf!"; b = "wtf!"
>>> a is b # This will print True or False depending on where you're invoking it (python shell / ipython / as a script)
False
```

```py
# This time in file some_file.py
a = "wtf!"
b = "wtf!"
print(a is b)
assert a is b
```

3\. `True` because it is invoked in script. Might be `False` in `python shell` or `ipython`

```python:snippets/2_tricky_strings.py -s 15 -e 19
a, b = "wtf!", "wtf!"
assert a is b

# prints True when the module is invoked!
a = "wtf!"; b = "wtf!"
assert a is b
```

4\.
4\. __Disclaimer - snippet is not relavant in modern Python versions__

**Output (< Python3.7 )**

Expand Down
13 changes: 13 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from typing import TYPE_CHECKING

import nox


if TYPE_CHECKING:
from nox.sessions import Session

python_versions = ["3.9", "3.10", "3.11", "3.12", "3.13"]

@nox.session(python=python_versions, reuse_venv=True)
def tests(session: "Session") -> None:
_ = session.run("python", "snippets/2_tricky_strings.py")
155 changes: 155 additions & 0 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[tool.poetry]
name = "wtfpython"
version = "3.0.0"
description = "What the f*ck Python!"
authors = ["Satwik Kansal <[email protected]>"]
license = "WTFPL 2.0"
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.9"
nox = "^2024.10.9"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
19 changes: 19 additions & 0 deletions snippets/2_tricky_strings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 1
assert id("some_string") == id("some" + "_" + "string")
assert id("some_string") == id("some_string")
satwikkansal marked this conversation as resolved.
Show resolved Hide resolved

# 2
a = "wtf"
b = "wtf"
assert a is b

a = "wtf!"
b = "wtf!"
assert a is b

# 3
a, b = "wtf!", "wtf!"
assert a is b

a = "wtf!"; b = "wtf!"
assert a is b
Empty file added snippets/__init__.py
Empty file.
Loading