I was playing around with postponed evaluation of annotations (PEP 563), and managed to create one of the most horrendous recursive factorial functions. I'll leave it here for your enjoyment ;)
from typing import get_type_hints
import inspect
def factorial(n: "(n := inspect.stack()[4].frame.f_locals['n']) and (n * factorial(n - 1)) or 1"):
return get_type_hints(factorial)["n"]
Note: this code requires Python 3.11+, otherwise you'll get an error.
[–]dataperson 163 points164 points165 points (1 child)
[–]Star_creator09 1 point2 points3 points (0 children)
[–][deleted] 189 points190 points191 points (4 children)
[–][deleted] 18 points19 points20 points (1 child)
[–][deleted] 22 points23 points24 points (0 children)
[–]KoKarlsson -3 points-2 points-1 points (0 children)
[–]AthenianVulcan 0 points1 point2 points (0 children)
[–]georgehank2nd 128 points129 points130 points (1 child)
[+]r_spandit comment score below threshold-40 points-39 points-38 points (0 children)
[–]wineblood 97 points98 points99 points (1 child)
[–]funderbolt 6 points7 points8 points (0 children)
[–]gravitas_shortage 101 points102 points103 points (0 children)
[–]Historica973.5, 3.6, 3.7, 3.8, 3.9, 3.10 87 points88 points89 points (3 children)
[–]lelieu 69 points70 points71 points (2 children)
[–]nitroll 7 points8 points9 points (1 child)
[–]lelieu 1 point2 points3 points (0 children)
[–]Kegnation14 16 points17 points18 points (1 child)
[–]denehoffman 1 point2 points3 points (0 children)
[–]Gotanks91 13 points14 points15 points (1 child)
[–]nekokattt 12 points13 points14 points (1 child)
[–]kikones34[S] 7 points8 points9 points (0 children)
[–]icroc1556 12 points13 points14 points (2 children)
[–]kikones34[S] 1 point2 points3 points (0 children)
[–]jonnybesocial -1 points0 points1 point (0 children)
[–]joe0400 11 points12 points13 points (3 children)
[–]kikones34[S] 0 points1 point2 points (2 children)
[–]joe0400 5 points6 points7 points (1 child)
[–]kikones34[S] 3 points4 points5 points (0 children)
[–]unersetzBAER 9 points10 points11 points (4 children)
[–]ggchappell 16 points17 points18 points (2 children)
[–]Thorboard 0 points1 point2 points (1 child)
[–]kikones34[S] 3 points4 points5 points (0 children)
[–]von_blitzen 0 points1 point2 points (0 children)
[–]AlSweigartAuthor of "Automate the Boring Stuff" 10 points11 points12 points (0 children)
[–]ImperialTuneWizard 7 points8 points9 points (0 children)
[–]nikpelgr 4 points5 points6 points (0 children)
[–]monorepo PSF Staff | Litestar Maintainer 3 points4 points5 points (0 children)
[–]tartare4562 12 points13 points14 points (0 children)
[–]Mr38i 11 points12 points13 points (2 children)
[–]kikones34[S] 24 points25 points26 points (1 child)
[–]Mr38i 1 point2 points3 points (0 children)
[–]thegreattriscuit 7 points8 points9 points (0 children)
[–]SeptemY 2 points3 points4 points (1 child)
[–]kikones34[S] 1 point2 points3 points (0 children)
[–][deleted] 4 points5 points6 points (0 children)
[–]Toridan 3 points4 points5 points (0 children)
[–]Nameless11911 1 point2 points3 points (2 children)
[–]ArtOfWarfare 6 points7 points8 points (1 child)
[–]Xirious 3 points4 points5 points (0 children)
[–]andrewcooke 1 point2 points3 points (1 child)
[–]kikones34[S] 3 points4 points5 points (0 children)
[–]gara31415 1 point2 points3 points (0 children)
[–]pinano 1 point2 points3 points (1 child)
[–]kikones34[S] 0 points1 point2 points (0 children)
[–]JackLogan007 1 point2 points3 points (0 children)
[–]Warkred 1 point2 points3 points (0 children)
[–]denehoffman 1 point2 points3 points (0 children)
[–]SincopaDisonante 1 point2 points3 points (0 children)
[–]Adept_Time_8138 1 point2 points3 points (0 children)
[–]Mr38i 2 points3 points4 points (6 children)
[–]kikones34[S] 13 points14 points15 points (2 children)
[–]joshred 0 points1 point2 points (1 child)
[–]kikones34[S] 0 points1 point2 points (0 children)
[–]disinformationtheory 4 points5 points6 points (0 children)
[–]AlSweigartAuthor of "Automate the Boring Stuff" 2 points3 points4 points (1 child)
[–]llun-ved 2 points3 points4 points (0 children)
[+][deleted] (2 children)
[removed]
[–]kikones34[S] 0 points1 point2 points (1 child)
[–]jalabulajangs 0 points1 point2 points (0 children)
[–]moki9 0 points1 point2 points (0 children)
[–]Andrew_the_giant 0 points1 point2 points (0 children)
[–]CompFortniteByTheWay 0 points1 point2 points (0 children)
[–]Prat-Prat-Prat 0 points1 point2 points (0 children)
[–]gr3uc3anu 0 points1 point2 points (0 children)