diff --git a/README.md b/README.md index d026d5f..d6b6e17 100644 --- a/README.md +++ b/README.md @@ -289,53 +289,37 @@ This saved one line of code, and implicitly prevented invoking `some_func` twice ### ▶ Strings can be tricky sometimes -1\. -```py ->>> a = "some_string" ->>> id(a) -140420665652016 ->>> id("some" + "_" + "string") # Notice that both the ids are same. -140420665652016 +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") ``` -2\. +2\. `True` because it is invoked in script. Might be `False` in `python shell` or `ipython` -```py ->>> a = "wtf" ->>> b = "wtf" ->>> a is b -True +```python:snippets/2_tricky_strings.py -s 6 -e 12 +a = "wtf" +b = "wtf" +assert a is b ->>> a = "wtf!" ->>> b = "wtf!" ->>> a is b -False - -``` - -3\. - -```py ->>> a, b = "wtf!", "wtf!" ->>> a is b # All versions except 3.7.x -True - ->>> 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) - -# prints True when the module is invoked! +assert a is b ``` -4\. +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 + +a = "wtf!"; b = "wtf!" +assert a is b +``` + +4\. __Disclaimer - snippet is not relavant in modern Python versions__ **Output (< Python3.7 )** diff --git a/noxfile.py b/noxfile.py new file mode 100644 index 0000000..f693b85 --- /dev/null +++ b/noxfile.py @@ -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") diff --git a/poetry.lock b/poetry.lock new file mode 100644 index 0000000..47b3498 --- /dev/null +++ b/poetry.lock @@ -0,0 +1,155 @@ +# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. + +[[package]] +name = "argcomplete" +version = "3.5.1" +description = "Bash tab completion for argparse" +optional = false +python-versions = ">=3.8" +files = [ + {file = "argcomplete-3.5.1-py3-none-any.whl", hash = "sha256:1a1d148bdaa3e3b93454900163403df41448a248af01b6e849edc5ac08e6c363"}, + {file = "argcomplete-3.5.1.tar.gz", hash = "sha256:eb1ee355aa2557bd3d0145de7b06b2a45b0ce461e1e7813f5d066039ab4177b4"}, +] + +[package.extras] +test = ["coverage", "mypy", "pexpect", "ruff", "wheel"] + +[[package]] +name = "colorama" +version = "0.4.6" +description = "Cross-platform colored terminal text." +optional = false +python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7" +files = [ + {file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"}, + {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, +] + +[[package]] +name = "colorlog" +version = "6.8.2" +description = "Add colours to the output of Python's logging module." +optional = false +python-versions = ">=3.6" +files = [ + {file = "colorlog-6.8.2-py3-none-any.whl", hash = "sha256:4dcbb62368e2800cb3c5abd348da7e53f6c362dda502ec27c560b2e58a66bd33"}, + {file = "colorlog-6.8.2.tar.gz", hash = "sha256:3e3e079a41feb5a1b64f978b5ea4f46040a94f11f0e8bbb8261e3dbbeca64d44"}, +] + +[package.dependencies] +colorama = {version = "*", markers = "sys_platform == \"win32\""} + +[package.extras] +development = ["black", "flake8", "mypy", "pytest", "types-colorama"] + +[[package]] +name = "distlib" +version = "0.3.9" +description = "Distribution utilities" +optional = false +python-versions = "*" +files = [ + {file = "distlib-0.3.9-py2.py3-none-any.whl", hash = "sha256:47f8c22fd27c27e25a65601af709b38e4f0a45ea4fc2e710f65755fa8caaaf87"}, + {file = "distlib-0.3.9.tar.gz", hash = "sha256:a60f20dea646b8a33f3e7772f74dc0b2d0772d2837ee1342a00645c81edf9403"}, +] + +[[package]] +name = "filelock" +version = "3.16.1" +description = "A platform independent file lock." +optional = false +python-versions = ">=3.8" +files = [ + {file = "filelock-3.16.1-py3-none-any.whl", hash = "sha256:2082e5703d51fbf98ea75855d9d5527e33d8ff23099bec374a134febee6946b0"}, + {file = "filelock-3.16.1.tar.gz", hash = "sha256:c249fbfcd5db47e5e2d6d62198e565475ee65e4831e2561c8e313fa7eb961435"}, +] + +[package.extras] +docs = ["furo (>=2024.8.6)", "sphinx (>=8.0.2)", "sphinx-autodoc-typehints (>=2.4.1)"] +testing = ["covdefaults (>=2.3)", "coverage (>=7.6.1)", "diff-cover (>=9.2)", "pytest (>=8.3.3)", "pytest-asyncio (>=0.24)", "pytest-cov (>=5)", "pytest-mock (>=3.14)", "pytest-timeout (>=2.3.1)", "virtualenv (>=20.26.4)"] +typing = ["typing-extensions (>=4.12.2)"] + +[[package]] +name = "nox" +version = "2024.10.9" +description = "Flexible test automation." +optional = false +python-versions = ">=3.8" +files = [ + {file = "nox-2024.10.9-py3-none-any.whl", hash = "sha256:1d36f309a0a2a853e9bccb76bbef6bb118ba92fa92674d15604ca99adeb29eab"}, + {file = "nox-2024.10.9.tar.gz", hash = "sha256:7aa9dc8d1c27e9f45ab046ffd1c3b2c4f7c91755304769df231308849ebded95"}, +] + +[package.dependencies] +argcomplete = ">=1.9.4,<4" +colorlog = ">=2.6.1,<7" +packaging = ">=20.9" +tomli = {version = ">=1", markers = "python_version < \"3.11\""} +virtualenv = ">=20.14.1" + +[package.extras] +tox-to-nox = ["jinja2", "tox"] +uv = ["uv (>=0.1.6)"] + +[[package]] +name = "packaging" +version = "24.1" +description = "Core utilities for Python packages" +optional = false +python-versions = ">=3.8" +files = [ + {file = "packaging-24.1-py3-none-any.whl", hash = "sha256:5b8f2217dbdbd2f7f384c41c628544e6d52f2d0f53c6d0c3ea61aa5d1d7ff124"}, + {file = "packaging-24.1.tar.gz", hash = "sha256:026ed72c8ed3fcce5bf8950572258698927fd1dbda10a5e981cdf0ac37f4f002"}, +] + +[[package]] +name = "platformdirs" +version = "4.3.6" +description = "A small Python package for determining appropriate platform-specific dirs, e.g. a `user data dir`." +optional = false +python-versions = ">=3.8" +files = [ + {file = "platformdirs-4.3.6-py3-none-any.whl", hash = "sha256:73e575e1408ab8103900836b97580d5307456908a03e92031bab39e4554cc3fb"}, + {file = "platformdirs-4.3.6.tar.gz", hash = "sha256:357fb2acbc885b0419afd3ce3ed34564c13c9b95c89360cd9563f73aa5e2b907"}, +] + +[package.extras] +docs = ["furo (>=2024.8.6)", "proselint (>=0.14)", "sphinx (>=8.0.2)", "sphinx-autodoc-typehints (>=2.4)"] +test = ["appdirs (==1.4.4)", "covdefaults (>=2.3)", "pytest (>=8.3.2)", "pytest-cov (>=5)", "pytest-mock (>=3.14)"] +type = ["mypy (>=1.11.2)"] + +[[package]] +name = "tomli" +version = "2.0.2" +description = "A lil' TOML parser" +optional = false +python-versions = ">=3.8" +files = [ + {file = "tomli-2.0.2-py3-none-any.whl", hash = "sha256:2ebe24485c53d303f690b0ec092806a085f07af5a5aa1464f3931eec36caaa38"}, + {file = "tomli-2.0.2.tar.gz", hash = "sha256:d46d457a85337051c36524bc5349dd91b1877838e2979ac5ced3e710ed8a60ed"}, +] + +[[package]] +name = "virtualenv" +version = "20.27.0" +description = "Virtual Python Environment builder" +optional = false +python-versions = ">=3.8" +files = [ + {file = "virtualenv-20.27.0-py3-none-any.whl", hash = "sha256:44a72c29cceb0ee08f300b314848c86e57bf8d1f13107a5e671fb9274138d655"}, + {file = "virtualenv-20.27.0.tar.gz", hash = "sha256:2ca56a68ed615b8fe4326d11a0dca5dfbe8fd68510fb6c6349163bed3c15f2b2"}, +] + +[package.dependencies] +distlib = ">=0.3.7,<1" +filelock = ">=3.12.2,<4" +platformdirs = ">=3.9.1,<5" + +[package.extras] +docs = ["furo (>=2023.7.26)", "proselint (>=0.13)", "sphinx (>=7.1.2,!=7.3)", "sphinx-argparse (>=0.4)", "sphinxcontrib-towncrier (>=0.2.1a0)", "towncrier (>=23.6)"] +test = ["covdefaults (>=2.3)", "coverage (>=7.2.7)", "coverage-enable-subprocess (>=1)", "flaky (>=3.7)", "packaging (>=23.1)", "pytest (>=7.4)", "pytest-env (>=0.8.2)", "pytest-freezer (>=0.4.8)", "pytest-mock (>=3.11.1)", "pytest-randomly (>=3.12)", "pytest-timeout (>=2.1)", "setuptools (>=68)", "time-machine (>=2.10)"] + +[metadata] +lock-version = "2.0" +python-versions = "^3.9" +content-hash = "af91619c8e62e649ee538e51a248ef2fc1e4f4495e7748b3b551685aa47b404e" diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..a048faf --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,16 @@ +[tool.poetry] +name = "wtfpython" +version = "3.0.0" +description = "What the f*ck Python!" +authors = ["Satwik Kansal "] +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" diff --git a/snippets/2_tricky_strings.py b/snippets/2_tricky_strings.py new file mode 100644 index 0000000..25320f2 --- /dev/null +++ b/snippets/2_tricky_strings.py @@ -0,0 +1,19 @@ +# 1 +assert id("some_string") == id("some" + "_" + "string") +assert id("some_string") == id("some_string") + +# 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 diff --git a/snippets/__init__.py b/snippets/__init__.py new file mode 100644 index 0000000..e69de29