From b090182e3127d5aacc7e7388b8701dfff032e155 Mon Sep 17 00:00:00 2001 From: Axy Date: Mon, 19 Jan 2026 17:28:42 +0100 Subject: [PATCH] Complete The Codex: Mastering Python's Import Mysteries --- alchemy/__init__.py | 4 ++++ alchemy/elements.py | 14 ++++++++++++ alchemy/grimoire/__init__.py | 2 ++ alchemy/grimoire/spellbook.py | 7 ++++++ alchemy/grimoire/validator.py | 5 +++++ alchemy/potions.py | 27 ++++++++++++++++++++++ alchemy/transmutation/__init__.py | 2 ++ alchemy/transmutation/advanced.py | 15 +++++++++++++ alchemy/transmutation/basic.py | 11 +++++++++ ft_circular_curse.py | 29 ++++++++++++++++++++++++ ft_import_transmutation.py | 21 ++++++++++++++++++ ft_pathway_debate.py | 28 +++++++++++++++++++++++ ft_sacred_scroll.py | 37 +++++++++++++++++++++++++++++++ pyproject.toml | 2 ++ 14 files changed, 204 insertions(+) create mode 100644 alchemy/__init__.py create mode 100644 alchemy/elements.py create mode 100644 alchemy/grimoire/__init__.py create mode 100644 alchemy/grimoire/spellbook.py create mode 100644 alchemy/grimoire/validator.py create mode 100644 alchemy/potions.py create mode 100644 alchemy/transmutation/__init__.py create mode 100644 alchemy/transmutation/advanced.py create mode 100644 alchemy/transmutation/basic.py create mode 100644 ft_circular_curse.py create mode 100644 ft_import_transmutation.py create mode 100644 ft_pathway_debate.py create mode 100644 ft_sacred_scroll.py create mode 100644 pyproject.toml diff --git a/alchemy/__init__.py b/alchemy/__init__.py new file mode 100644 index 0000000..752c232 --- /dev/null +++ b/alchemy/__init__.py @@ -0,0 +1,4 @@ +from .elements import create_fire, create_water # noqa: F401 + +__version__ = "1.0.0" +__author__ = "Master Pythonicus" diff --git a/alchemy/elements.py b/alchemy/elements.py new file mode 100644 index 0000000..5cf59ed --- /dev/null +++ b/alchemy/elements.py @@ -0,0 +1,14 @@ +def create_fire(): + return "Fire element created" + + +def create_water(): + return "Water element created" + + +def create_earth(): + return "Earth element created" + + +def create_air(): + return "Air element created" diff --git a/alchemy/grimoire/__init__.py b/alchemy/grimoire/__init__.py new file mode 100644 index 0000000..b759fe9 --- /dev/null +++ b/alchemy/grimoire/__init__.py @@ -0,0 +1,2 @@ +from .spellbook import record_spell # noqa: F401 +from .validator import validate_ingredients # noqa: F401 diff --git a/alchemy/grimoire/spellbook.py b/alchemy/grimoire/spellbook.py new file mode 100644 index 0000000..c3f4e06 --- /dev/null +++ b/alchemy/grimoire/spellbook.py @@ -0,0 +1,7 @@ +def record_spell(spell_name: str, ingredients: str) -> str: + from .validator import validate_ingredients + + validation_result = validate_ingredients(ingredients) + if validation_result.endswith(" - VALID"): + return f"Spell recorded: {spell_name} ({validation_result})" + return f"Spell rejected: {spell_name} ({validation_result})" diff --git a/alchemy/grimoire/validator.py b/alchemy/grimoire/validator.py new file mode 100644 index 0000000..416311d --- /dev/null +++ b/alchemy/grimoire/validator.py @@ -0,0 +1,5 @@ +def validate_ingredients(ingredients: str) -> str: + valid_elements = ["fire", "water", "earth", "air"] + if any(element in ingredients.lower() for element in valid_elements): + return f"{ingredients} - VALID" + return f"{ingredients} - INVALID" diff --git a/alchemy/potions.py b/alchemy/potions.py new file mode 100644 index 0000000..b03b253 --- /dev/null +++ b/alchemy/potions.py @@ -0,0 +1,27 @@ +from .elements import create_fire, create_water, create_earth, create_air + + +def healing_potion(): + fire_result = create_fire() + water_result = create_water() + return f"Healing potion brewed with {fire_result} and {water_result}" + + +def strength_potion(): + earth_result = create_earth() + fire_result = create_fire() + return f"Strength potion brewed with {earth_result} and {fire_result}" + + +def invisibility_potion(): + air_result = create_air() + water_result = create_water() + return f"Invisibility potion brewed with {air_result} and {water_result}" + + +def wisdom_potion(): + all_four_results = ( + f"{create_fire()}, {create_water()}, " + f"{create_earth()} and {create_air()}" + ) + return f"Wisdom potion brewed with all elements: {all_four_results}" diff --git a/alchemy/transmutation/__init__.py b/alchemy/transmutation/__init__.py new file mode 100644 index 0000000..60aa231 --- /dev/null +++ b/alchemy/transmutation/__init__.py @@ -0,0 +1,2 @@ +from .basic import lead_to_gold, stone_to_gem # noqa: F401 +from .advanced import philosophers_stone, elixir_of_life # noqa: F401 diff --git a/alchemy/transmutation/advanced.py b/alchemy/transmutation/advanced.py new file mode 100644 index 0000000..9c06ed3 --- /dev/null +++ b/alchemy/transmutation/advanced.py @@ -0,0 +1,15 @@ +from .basic import lead_to_gold +from ..potions import healing_potion + + +def philosophers_stone(): + lead_to_gold_result = lead_to_gold() + healing_potion_result = healing_potion() + return ( + f"Philosopher's stone created using {lead_to_gold_result} and " + f"{healing_potion_result}" + ) + + +def elixir_of_life(): + return "Elixir of life: eternal youth achieved!" diff --git a/alchemy/transmutation/basic.py b/alchemy/transmutation/basic.py new file mode 100644 index 0000000..9c866cc --- /dev/null +++ b/alchemy/transmutation/basic.py @@ -0,0 +1,11 @@ +from alchemy.elements import create_fire, create_earth + + +def lead_to_gold(): + fire_result = create_fire() + return f"Lead transmuted to gold using {fire_result}" + + +def stone_to_gem(): + earth_result = create_earth() + return f"Stone transmuted to gem using {earth_result}" diff --git a/ft_circular_curse.py b/ft_circular_curse.py new file mode 100644 index 0000000..f320ba4 --- /dev/null +++ b/ft_circular_curse.py @@ -0,0 +1,29 @@ +from alchemy.grimoire import validate_ingredients, record_spell + +print("=== Circular Curse Breaking ===\n") + +print("Testing ingredient validation:") +print(f'validate_ingredients("fire air"): {validate_ingredients("fire air")}') +print( + f'validate_ingredients("dragon scales"): ' + f'{validate_ingredients("dragon scales")}\n' +) + +print("Testing spell recording with validation:") +print( + f'record_spell("Fireball", "fire air"): ' + f'{record_spell("Fireball", "fire air")}' +) +print( + f'record_spell("Dark Magic", "shadow"): ' + f'{record_spell("Dark Magic", "shadow")}\n' +) + +print("Testing late import technique:") +print( + f'record_spell("Lightning", "air"): ' + f'{record_spell("Lightning", "air")}\n' +) + +print("Circular dependency curse avoided using late imports!") +print("All spells processed safely!") diff --git a/ft_import_transmutation.py b/ft_import_transmutation.py new file mode 100644 index 0000000..39d7f95 --- /dev/null +++ b/ft_import_transmutation.py @@ -0,0 +1,21 @@ +print("=== Import Transmutation Mastery ===\n") +print("Method 1 - Full module import:") +import alchemy.elements # noqa: E402 + +print(f"alchemy.elements.create_fire(): {alchemy.elements.create_fire()}\n") +print("Method 2 - Specific function import:") +from alchemy.elements import create_water # noqa: E402 + +print(f"create_water(): {create_water()}\n") +print("Method 3 - Aliased import:") +from alchemy.potions import healing_potion as heal # noqa: E402 + +print(f"heal(): {heal()}\n") +print("Method 4 - Multiple imports:") +from alchemy.elements import create_earth, create_fire # noqa: E402 +from alchemy.potions import strength_potion # noqa: E402 + +print(f"create_earth(): {create_earth()}") +print(f"create_fire(): {create_fire()}") +print(f"strength_potion(): {strength_potion()}\n") +print("All import transmutation methods mastered!") diff --git a/ft_pathway_debate.py b/ft_pathway_debate.py new file mode 100644 index 0000000..997dd79 --- /dev/null +++ b/ft_pathway_debate.py @@ -0,0 +1,28 @@ +import alchemy.transmutation.basic +import alchemy.transmutation.advanced +import alchemy.transmutation + +print("=== Pathway Debate Mastery ===\n") + +print("Testing Absolute Imports (from basic.py):") +print(f"lead_to_gold(): {alchemy.transmutation.basic.lead_to_gold()}") +print(f"stone_to_gem(): {alchemy.transmutation.basic.stone_to_gem()}\n") + +print("Testing Relative Imports (from advanced.py):") +print( + "philosophers_stone(): " + f"{alchemy.transmutation.advanced.philosophers_stone()}" +) +print(f"elixir_of_life(): {alchemy.transmutation.advanced.elixir_of_life()}\n") + +print("Testing Package Access:") +print( + "alchemy.transmutation.lead_to_gold(): " + f"{alchemy.transmutation.lead_to_gold()}" +) +print( + "alchemy.transmutation.philosophers_stone(): " + f"{alchemy.transmutation.philosophers_stone()}\n" +) + +print("Both pathways work! Absolute: clear, Relative: concise") diff --git a/ft_sacred_scroll.py b/ft_sacred_scroll.py new file mode 100644 index 0000000..0ddc1cb --- /dev/null +++ b/ft_sacred_scroll.py @@ -0,0 +1,37 @@ +import alchemy +import alchemy.elements + +print("=== Sacred Scroll Mastery ===\n") + +print("Testing direct module access:") +print(f"alchemy.elements.create_fire(): {alchemy.elements.create_fire()}") +print(f"alchemy.elements.create_water(): {alchemy.elements.create_water()}") +print(f"alchemy.elements.create_earth(): {alchemy.elements.create_earth()}") +print(f"alchemy.elements.create_air(): {alchemy.elements.create_air()}") +print() + +print("Testing package-level access (controlled by __init__.py):") +try: + print(f"alchemy.create_fire(): {alchemy.create_fire()}") +except AttributeError as e: + print(f"alchemy.create_fire(): AttributeError - {e}") + +try: + print(f"alchemy.create_water(): {alchemy.create_water()}") +except AttributeError as e: + print(f"alchemy.create_water(): AttributeError - {e}") + +try: + print(f"alchemy.create_earth(): {alchemy.create_earth()}") +except AttributeError: + print("alchemy.create_earth(): AttributeError - not exposed") + +try: + print(f"alchemy.create_air(): {alchemy.create_air()}") +except AttributeError: + print("alchemy.create_air(): AttributeError - not exposed") +print() + +print("Package metadata:") +print(f"Version: {alchemy.__version__}") +print(f"Author: {alchemy.__author__}") diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..a8f43fe --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,2 @@ +[tool.black] +line-length = 79 -- 2.52.0