-
Notifications
You must be signed in to change notification settings - Fork 0
Домашнее задание 7.1. Каррирование. Разгуляева А.И. #6
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
Open
ada1ra
wants to merge
2
commits into
main
Choose a base branch
from
hw_7_1_curry
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| # ruff.toml | ||
| target-version = "py311" | ||
| line-length = 100 | ||
|
|
||
| # включить все основные правила | ||
| select = [ | ||
| "E", # pycodestyle errors | ||
| "W", # pycodestyle warnings | ||
| "F", # Pyflakes | ||
| "I", # isort | ||
| "N", # pep8-naming | ||
| "UP", # pyupgrade | ||
| "YTT", # flake8-2020 | ||
| "S", # flake8-bandit | ||
| "A", # flake8-builtins | ||
| "COM", # flake8-commas | ||
| "C4", # flake8-comprehensions | ||
| "DTZ", # flake8-datetimez | ||
| "T10", # flake8-debugger | ||
| "EM", # flake8-errmsg | ||
| "EXE", # flake8-executable | ||
| "ISC", # flake8-implicit-str-concat | ||
| "ICN", # flake8-import-conventions | ||
| "G", # flake8-logging-format | ||
| "INP", # flake8-no-pep420 | ||
| "PIE", # flake8-pie | ||
| "T20", # flake8-print | ||
| "PYI", # flake8-pyi | ||
| "PT", # flake8-pytest-style | ||
| "Q", # flake8-quotes | ||
| "RSE", # flake8-raise | ||
| "RET", # flake8-return | ||
| "SLF", # flake8-self | ||
| "SIM", # flake8-simplify | ||
| "TID", # flake8-tidy-imports | ||
| "TCH", # flake8-type-checking | ||
| "INT", # flake8-gettext | ||
| "ARG", # flake8-unused-arguments | ||
| "FBT", # flake8-boolean-trap | ||
| "B", # flake8-bugbear | ||
| "AIR", # flake8-airflow | ||
| "PERF", # flake8-perflint | ||
| ] | ||
|
|
||
| # игнорировать правила | ||
| ignore = [ | ||
| "E501", # line too long - handled by formatter | ||
| "S101", # assert used - ok in tests | ||
| "T201", # print found - sometimes needed | ||
| "COM812", # trailing comma missing - not always required | ||
| ] | ||
|
|
||
| # настройки для конкретных файлов | ||
| [per-file-ignores] | ||
| "__init__.py" = ["F401"] # Unused imports allowed in __init__.py | ||
| "tests/**" = ["S101", "SLF001"] # Allow assert and self in tests | ||
| "**/migrations/**" = ["ALL"] # Ignore all in migrations | ||
|
|
||
| # настройки форматтера | ||
| [format] | ||
| indent-style = "space" | ||
| quote-style = "double" | ||
| skip-magic-trailing-comma = false | ||
| line-ending = "auto" | ||
|
|
||
| # настройки для конкретных правил | ||
| [flake8-quotes] | ||
| docstring-quotes = "double" | ||
| inline-quotes = "double" | ||
|
|
||
| [flake8-tidy-imports] | ||
| ban-relative-imports = "all" | ||
|
|
||
| [isort] | ||
| known-first-party = ["myapp"] | ||
| lines-after-imports = 2 | ||
| combine-as-imports = true | ||
| split-on-trailing-comma = true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| def curry(func, arity): | ||
| if arity < 0: | ||
| raise ValueError("Арность не может быть отрицательной") | ||
|
|
||
| def curried(*args): | ||
| if len(args) >= arity: | ||
| return func(*args[:arity]) | ||
| else: | ||
| def next_function(x): | ||
| new_args = args + (x,) | ||
| return curried(*new_args) | ||
|
|
||
| return next_function | ||
|
|
||
| return curried | ||
|
|
||
|
|
||
| def uncurry(curried_func, arity): | ||
| if arity < 0: | ||
| raise ValueError("Арность не может быть отрицательной") | ||
|
|
||
| def uncurried(*args): | ||
| if len(args) != arity: | ||
| raise TypeError(f"Ожидается {arity} аргументов, получено {len(args)}") | ||
|
|
||
| result = curried_func | ||
| for arg in args: | ||
| result = result(arg) | ||
| return result | ||
|
|
||
| return uncurried | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Добавить проверки:
Что n -- это целое число;
Что n не превышает реальное количество аргументов func.