{"id":15008912,"url":"https://github.com/fklc/namedassignments","last_synced_at":"2025-10-03T17:31:19.215Z","repository":{"id":114025841,"uuid":"169956514","full_name":"FKLC/NamedAssignments","owner":"FKLC","description":"Really small library to implement NamedExpressions in PEP 572 for Python \u003c=3.7 ","archived":true,"fork":false,"pushed_at":"2019-02-14T14:27:02.000Z","size":3,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-09-29T16:22:29.813Z","etag":null,"topics":["pep","pep572","python","python-2","python-3","python-3-6","python2","python27","python3","python36"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/FKLC.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-02-10T08:13:05.000Z","updated_at":"2023-02-18T14:18:06.000Z","dependencies_parsed_at":null,"dependency_job_id":"f0c6df47-1908-4e6b-a0dd-ebb9239930b9","html_url":"https://github.com/FKLC/NamedAssignments","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FKLC%2FNamedAssignments","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FKLC%2FNamedAssignments/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FKLC%2FNamedAssignments/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FKLC%2FNamedAssignments/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FKLC","download_url":"https://codeload.github.com/FKLC/NamedAssignments/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235165449,"owners_count":18946240,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["pep","pep572","python","python-2","python-3","python-3-6","python2","python27","python3","python36"],"created_at":"2024-09-24T19:21:42.030Z","updated_at":"2025-10-03T17:31:18.915Z","avatar_url":"https://github.com/FKLC.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NamedAssignments\nNamedAssignments is a library that I developed for myself to use named assignments in my Python \u003c= 3.7 projects.\n\n## What is named assignments?\nActual thing I don't even know how should I call them but this is the best name I found for them. If you've read [PEP 572](https://www.python.org/dev/peps/pep-0572/) there is a new operator coming in Python 3.8 called as ***Named Expressions*** (this is how it is going to look like in your code `:=`) which helps you to write more clean and shorter code.\n\n## But how?\nFor original examples you can check [PEP 572 examples](https://www.python.org/dev/peps/pep-0572/#examples) directly but if you are looking this library you are probably not using Python 3.8 so just stay in here and continue reading.\n\n\n* Caching computationally expensive computations (This is definitely a bad example of expensive computation but lets just act like it is)\n  ###### Old way:\n\n  ```python\n  # Makes two addition every time\n  strange_list = [[x + 1, x/(x + 1)] for x in range(5)]\n  ```\n  ###### Improved:\n\n  ```python\n  # Makes only one addition every time\n  strange_list = [[N('y', lambda: x + 1), x/N.y] for x in range(5)]\n  ```\n\n* Usage in while loops\n  ###### Old way:\n\n  ```python\n  # conn is a accepted socket connection\n  while True:\n      data = conn.recv(1024)\n      if not data:\n          break\n      conn.sendall(data)\n  ```\n  ###### Improved:\n\n  ```python\n  # conn is a accepted socket connection\n  while N('data', conn.recv, 1024):\n      conn.sendall(N.data)\n  ```\n\n## Usage\nUsage is not clean as original due to limitations but it is the cleanest way I found.\n```python\nfrom namedassignments import NamedAssignments as N\n\nN(variable_name, function, *args, **kwargs)\n```\n\n## Installation\nLibrary is avaible on PyPi so just run\n```\npip install namedassignments\n```\n\n## API\nSince the whole code is only 5 lines there is nothing too much. Library uses Python's magic method `__new__` to return what function returns this is all library does on the background.\n* `__new__` Arguments:\n  * `variable_name`: Variable name you want to use while retrieving data. (String) (Required)\n  * `function`: Function you want to execute. (Function) (Required)\n  * `*args`: Arguments you want to pass function. (List) (Optional)\n  * `**kwargs`: Keyword arguments you want to pass function. (Dict) (Optional)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffklc%2Fnamedassignments","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffklc%2Fnamedassignments","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffklc%2Fnamedassignments/lists"}