From dd927e8f5c7564bdec546abe6511842f9b5bf4b5 Mon Sep 17 00:00:00 2001 From: zyd Date: Mon, 16 May 2022 02:57:02 +0900 Subject: [PATCH 1/5] git add pycln --- .pre-commit-config.yaml | 5 +++++ pyproject.toml | 2 ++ 2 files changed, 7 insertions(+) create mode 100644 pyproject.toml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c8db207..08b3608 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -12,3 +12,8 @@ repos: rev: 5.5.2 hooks: - id: isort +- repo: https://github.com/hadialqattan/pycln + rev: v1.3.1 # Possible releases: https://github.com/hadialqattan/pycln/releases + hooks: + - id: pycln + args: [--config=pyproject.toml] diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..08ea115 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,2 @@ +[tool.pycln] +all = true From baf665eeb5469ed662cf731ffa07e3bd9b54f9da Mon Sep 17 00:00:00 2001 From: zyd Date: Mon, 16 May 2022 03:09:28 +0900 Subject: [PATCH 2/5] add pylint --- .pre-commit-config.yaml | 15 +- README.md | 1 + pylintrc | 564 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 579 insertions(+), 1 deletion(-) create mode 100644 pylintrc diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 08b3608..26f8084 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,7 +13,20 @@ repos: hooks: - id: isort - repo: https://github.com/hadialqattan/pycln - rev: v1.3.1 # Possible releases: https://github.com/hadialqattan/pycln/releases + rev: v1.3.2 # Possible releases: https://github.com/hadialqattan/pycln/releases hooks: - id: pycln args: [--config=pyproject.toml] +- repo: local + hooks: + - id: pylint + name: pylint + entry: pylint + language: system + types: [python] + args: + [ + "-rn", # Only display messages + "-sn", # Don't display the score + "--rcfile=pylintrc", # Link to your config file + ] diff --git a/README.md b/README.md index b01da0e..31dd3d1 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ please check below `CheckList` for more details. For whom wants to contribute to this repo. ```bash +$ pip install -U pylint # see: https://pre-commit.com/ for more details $ pre-commit install # please install hooks first ``` diff --git a/pylintrc b/pylintrc new file mode 100644 index 0000000..5e7a619 --- /dev/null +++ b/pylintrc @@ -0,0 +1,564 @@ +[MAIN] + +# Specify a configuration file. +#rcfile= + +# Python code to execute, usually for sys.path manipulation such as +# pygtk.require(). +#init-hook= + +# Files or directories to be skipped. They should be base names, not +# paths. +ignore=CVS + +# Add files or directories matching the regex patterns to the ignore-list. The +# regex matches against paths and can be in Posix or Windows format. +ignore-paths= + +# Files or directories matching the regex patterns are skipped. The regex +# matches against base names, not paths. +ignore-patterns=^\.# + +# Pickle collected data for later comparisons. +persistent=yes + +# List of plugins (as comma separated values of python modules names) to load, +# usually to register additional checkers. +load-plugins= + pylint.extensions.check_elif, + pylint.extensions.bad_builtin, + pylint.extensions.docparams, + pylint.extensions.for_any_all, + pylint.extensions.set_membership, + pylint.extensions.code_style, + pylint.extensions.overlapping_exceptions, + pylint.extensions.typing, + pylint.extensions.redefined_variable_type, + pylint.extensions.comparison_placement, + +# Use multiple processes to speed up Pylint. Specifying 0 will auto-detect the +# number of processors available to use. +jobs=1 + +# When enabled, pylint would attempt to guess common misconfiguration and emit +# user-friendly hints instead of false-positive error messages. +suggestion-mode=yes + +# Allow loading of arbitrary C extensions. Extensions are imported into the +# active Python interpreter and may run arbitrary code. +unsafe-load-any-extension=no + +# A comma-separated list of package or module names from where C extensions may +# be loaded. Extensions are loading into the active Python interpreter and may +# run arbitrary code +extension-pkg-allow-list= + +# Minimum supported python version +py-version = 3.7.2 + +# Control the amount of potential inferred values when inferring a single +# object. This can help the performance when dealing with large functions or +# complex, nested conditions. +limit-inference-results=100 + +# Specify a score threshold to be exceeded before program exits with error. +fail-under=10.0 + +# Return non-zero exit code if any of these messages/categories are detected, +# even if score is above --fail-under value. Syntax same as enable. Messages +# specified are enabled, while categories only check already-enabled messages. +fail-on= + + +[MESSAGES CONTROL] + +# Only show warnings with the listed confidence levels. Leave empty to show +# all. Valid levels: HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED +# confidence= + +# Enable the message, report, category or checker with the given id(s). You can +# either give multiple identifier separated by comma (,) or put this option +# multiple time (only on the command line, not in the configuration file where +# it should appear only once). See also the "--disable" option for examples. +enable= + use-symbolic-message-instead, + useless-suppression, + +# Disable the message, report, category or checker with the given id(s). You +# can either give multiple identifiers separated by comma (,) or put this +# option multiple times (only on the command line, not in the configuration +# file where it should appear only once).You can also use "--disable=all" to +# disable everything first and then re-enable specific checks. For example, if +# you want to run only the similarities checker, you can use "--disable=all +# --enable=similarities". If you want to run only the classes checker, but have +# no Warning level messages displayed, use"--disable=all --enable=classes +# --disable=W" + +disable= + attribute-defined-outside-init, + invalid-name, + missing-docstring, + protected-access, + too-few-public-methods, + # handled by black + format, + # We anticipate #3512 where it will become optional + fixme, + + +[REPORTS] + +# Set the output format. Available formats are text, parseable, colorized, msvs +# (visual studio) and html. You can also give a reporter class, eg +# mypackage.mymodule.MyReporterClass. +output-format=text + +# Tells whether to display a full report or only the messages +reports=no + +# Python expression which should return a note less than 10 (10 is the highest +# note). You have access to the variables 'fatal', 'error', 'warning', 'refactor', 'convention' +# and 'info', which contain the number of messages in each category, as +# well as 'statement', which is the total number of statements analyzed. This +# score is used by the global evaluation report (RP0004). +evaluation=max(0, 0 if fatal else 10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)) + +# Template used to display messages. This is a python new-style format string +# used to format the message information. See doc for all details +#msg-template= + +# Activate the evaluation score. +score=yes + + +[LOGGING] + +# Logging modules to check that the string format arguments are in logging +# function parameter format +logging-modules=logging + +# The type of string formatting that logging methods do. `old` means using % +# formatting, `new` is for `{}` formatting. +logging-format-style=old + + +[MISCELLANEOUS] + +# List of note tags to take in consideration, separated by a comma. +notes=FIXME,XXX,TODO + +# Regular expression of note tags to take in consideration. +#notes-rgx= + + +[SIMILARITIES] + +# Minimum lines number of a similarity. +min-similarity-lines=6 + +# Ignore comments when computing similarities. +ignore-comments=yes + +# Ignore docstrings when computing similarities. +ignore-docstrings=yes + +# Ignore imports when computing similarities. +ignore-imports=yes + +# Signatures are removed from the similarity computation +ignore-signatures=yes + + +[VARIABLES] + +# Tells whether we should check for unused import in __init__ files. +init-import=no + +# A regular expression matching the name of dummy variables (i.e. expectedly +# not used). +dummy-variables-rgx=_$|dummy + +# List of additional names supposed to be defined in builtins. Remember that +# you should avoid defining new builtins when possible. +additional-builtins= + +# List of strings which can identify a callback function by name. A callback +# name must start or end with one of those strings. +callbacks=cb_,_cb + +# Tells whether unused global variables should be treated as a violation. +allow-global-unused-variables=yes + +# List of names allowed to shadow builtins +allowed-redefined-builtins= + +# Argument names that match this expression will be ignored. Default to name +# with leading underscore. +ignored-argument-names=_.* + +# List of qualified module names which can have objects that can redefine +# builtins. +redefining-builtins-modules=six.moves,past.builtins,future.builtins,builtins,io + + +[FORMAT] + +# Maximum number of characters on a single line. +max-line-length=100 + +# Regexp for a line that is allowed to be longer than the limit. +ignore-long-lines=^\s*(# )??$ + +# Allow the body of an if to be on the same line as the test if there is no +# else. +single-line-if-stmt=no + +# Allow the body of a class to be on the same line as the declaration if body +# contains single statement. +single-line-class-stmt=no + +# Maximum number of lines in a module +max-module-lines=2000 + +# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 +# tab). +indent-string=' ' + +# Number of spaces of indent required inside a hanging or continued line. +indent-after-paren=4 + +# Expected format of line ending, e.g. empty (any line ending), LF or CRLF. +expected-line-ending-format= + + +[BASIC] + +# Good variable names which should always be accepted, separated by a comma +good-names=i,j,k,ex,Run,_ + +# Good variable names regexes, separated by a comma. If names match any regex, +# they will always be accepted +good-names-rgxs= + +# Bad variable names which should always be refused, separated by a comma +bad-names=foo,bar,baz,toto,tutu,tata + +# Bad variable names regexes, separated by a comma. If names match any regex, +# they will always be refused +bad-names-rgxs= + +# Colon-delimited sets of names that determine each other's naming style when +# the name regexes allow several styles. +name-group= + +# Include a hint for the correct naming format with invalid-name +include-naming-hint=no + +# Naming style matching correct function names. +function-naming-style=snake_case + +# Regular expression matching correct function names +function-rgx=[a-z_][a-z0-9_]{2,30}$ + +# Naming style matching correct variable names. +variable-naming-style=snake_case + +# Regular expression matching correct variable names +variable-rgx=[a-z_][a-z0-9_]{2,30}$ + +# Naming style matching correct constant names. +const-naming-style=UPPER_CASE + +# Regular expression matching correct constant names +const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ + +# Naming style matching correct attribute names. +attr-naming-style=snake_case + +# Regular expression matching correct attribute names +attr-rgx=[a-z_][a-z0-9_]{2,}$ + +# Naming style matching correct argument names. +argument-naming-style=snake_case + +# Regular expression matching correct argument names +argument-rgx=[a-z_][a-z0-9_]{2,30}$ + +# Naming style matching correct class attribute names. +class-attribute-naming-style=any + +# Regular expression matching correct class attribute names +class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ + +# Naming style matching correct class constant names. +class-const-naming-style=UPPER_CASE + +# Regular expression matching correct class constant names. Overrides class- +# const-naming-style. +#class-const-rgx= + +# Naming style matching correct inline iteration names. +inlinevar-naming-style=any + +# Regular expression matching correct inline iteration names +inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$ + +# Naming style matching correct class names. +class-naming-style=PascalCase + +# Regular expression matching correct class names +class-rgx=[A-Z_][a-zA-Z0-9]+$ + + +# Naming style matching correct module names. +module-naming-style=snake_case + +# Regular expression matching correct module names +module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ + + +# Naming style matching correct method names. +method-naming-style=snake_case + +# Regular expression matching correct method names +method-rgx=[a-z_][a-z0-9_]{2,}$ + +# Regular expression which can overwrite the naming style set by typevar-naming-style. +#typevar-rgx= + +# Regular expression which should only match function or class names that do +# not require a docstring. Use ^(?!__init__$)_ to also check __init__. +no-docstring-rgx=__.*__ + +# Minimum line length for functions/classes that require docstrings, shorter +# ones are exempt. +docstring-min-length=-1 + +# List of decorators that define properties, such as abc.abstractproperty. +property-classes=abc.abstractproperty + + +[TYPECHECK] + +# Regex pattern to define which classes are considered mixins if ignore-mixin- +# members is set to 'yes' +mixin-class-rgx=.*MixIn + +# List of module names for which member attributes should not be checked +# (useful for modules/projects where namespaces are manipulated during runtime +# and thus existing member attributes cannot be deduced by static analysis). It +# supports qualified module names, as well as Unix pattern matching. +ignored-modules= + +# List of class names for which member attributes should not be checked (useful +# for classes with dynamically set attributes). This supports the use of +# qualified names. +ignored-classes=SQLObject, optparse.Values, thread._local, _thread._local + +# List of members which are set dynamically and missed by pylint inference +# system, and so shouldn't trigger E1101 when accessed. Python regular +# expressions are accepted. +generated-members=REQUEST,acl_users,aq_parent,argparse.Namespace + +# List of decorators that create context managers from functions, such as +# contextlib.contextmanager. +contextmanager-decorators=contextlib.contextmanager + +# Tells whether to warn about missing members when the owner of the attribute +# is inferred to be None. +ignore-none=yes + +# This flag controls whether pylint should warn about no-member and similar +# checks whenever an opaque object is returned when inferring. The inference +# can return multiple potential results while evaluating a Python object, but +# some branches might not be evaluated, which results in partial inference. In +# that case, it might be useful to still emit no-member and other checks for +# the rest of the inferred objects. +ignore-on-opaque-inference=yes + +# Show a hint with possible names when a member name was not found. The aspect +# of finding the hint is based on edit distance. +missing-member-hint=yes + +# The minimum edit distance a name should have in order to be considered a +# similar match for a missing member name. +missing-member-hint-distance=1 + +# The total number of similar names that should be taken in consideration when +# showing a hint for a missing member. +missing-member-max-choices=1 + +[SPELLING] + +# Spelling dictionary name. Available dictionaries: none. To make it working +# install python-enchant package. +spelling-dict= + +# List of comma separated words that should not be checked. +spelling-ignore-words= + +# List of comma separated words that should be considered directives if they +# appear and the beginning of a comment and should not be checked. +spelling-ignore-comment-directives=fmt: on,fmt: off,noqa:,noqa,nosec,isort:skip,mypy:,pragma:,# noinspection + +# A path to a file that contains private dictionary; one word per line. +spelling-private-dict-file=.pyenchant_pylint_custom_dict.txt + +# Tells whether to store unknown words to indicated private dictionary in +# --spelling-private-dict-file option instead of raising a message. +spelling-store-unknown-words=no + +# Limits count of emitted suggestions for spelling mistakes. +max-spelling-suggestions=2 + + +[DESIGN] + +# Maximum number of arguments for function / method +max-args=10 + +# Maximum number of locals for function / method body +max-locals=25 + +# Maximum number of return / yield for function / method body +max-returns=11 + +# Maximum number of branch for function / method body +max-branches=27 + +# Maximum number of statements in function / method body +max-statements=100 + +# Maximum number of parents for a class (see R0901). +max-parents=7 + +# List of qualified class names to ignore when counting class parents (see R0901). +ignored-parents= + +# Maximum number of attributes for a class (see R0902). +max-attributes=11 + +# Minimum number of public methods for a class (see R0903). +min-public-methods=2 + +# Maximum number of public methods for a class (see R0904). +max-public-methods=25 + +# Maximum number of boolean expressions in an if statement (see R0916). +max-bool-expr=5 + +# List of regular expressions of class ancestor names to +# ignore when counting public methods (see R0903). +exclude-too-few-public-methods= + +[CLASSES] + +# List of method names used to declare (i.e. assign) instance attributes. +defining-attr-methods=__init__,__new__,setUp,__post_init__ + +# List of valid names for the first argument in a class method. +valid-classmethod-first-arg=cls + +# List of valid names for the first argument in a metaclass class method. +valid-metaclass-classmethod-first-arg=mcs + +# List of member names, which should be excluded from the protected access +# warning. +exclude-protected=_asdict,_fields,_replace,_source,_make + +# Warn about protected attribute access inside special methods +check-protected-access-in-special-methods=no + +[IMPORTS] + +# List of modules that can be imported at any level, not just the top level +# one. +allow-any-import-level= + +# Allow wildcard imports from modules that define __all__. +allow-wildcard-with-all=no + +# Analyse import fallback blocks. This can be used to support both Python 2 and +# 3 compatible code, which means that the block might have code that exists +# only in one or another interpreter, leading to false positives when analysed. +analyse-fallback-blocks=no + +# Deprecated modules which should not be used, separated by a comma +deprecated-modules=regsub,TERMIOS,Bastion,rexec + +# Create a graph of every (i.e. internal and external) dependencies in the +# given file (report RP0402 must not be disabled) +import-graph= + +# Create a graph of external dependencies in the given file (report RP0402 must +# not be disabled) +ext-import-graph= + +# Create a graph of internal dependencies in the given file (report RP0402 must +# not be disabled) +int-import-graph= + +# Force import order to recognize a module as part of the standard +# compatibility libraries. +known-standard-library= + +# Force import order to recognize a module as part of a third party library. +known-third-party=enchant + +# Couples of modules and preferred modules, separated by a comma. +preferred-modules= + + +[EXCEPTIONS] + +# Exceptions that will emit a warning when being caught. Defaults to +# "Exception" +overgeneral-exceptions=Exception + + +[TYPING] + +# Set to ``no`` if the app / library does **NOT** need to support runtime +# introspection of type annotations. If you use type annotations +# **exclusively** for type checking of an application, you're probably fine. +# For libraries, evaluate if some users what to access the type hints at +# runtime first, e.g., through ``typing.get_type_hints``. Applies to Python +# versions 3.7 - 3.9 +runtime-typing = no + + +[DEPRECATED_BUILTINS] + +# List of builtins function names that should not be used, separated by a comma +bad-functions=map,input + + +[REFACTORING] + +# Maximum number of nested blocks for function / method body +max-nested-blocks=5 + +# Complete name of functions that never returns. When checking for +# inconsistent-return-statements if a never returning function is called then +# it will be considered as an explicit return statement and no message will be +# printed. +never-returning-functions=sys.exit,argparse.parse_error + + +[STRING] + +# This flag controls whether inconsistent-quotes generates a warning when the +# character used as a quote delimiter is used inconsistently within a module. +check-quote-consistency=no + +# This flag controls whether the implicit-str-concat should generate a warning +# on implicit string concatenation in sequences defined over several lines. +check-str-concat-over-line-jumps=no + + +[CODE_STYLE] + +# Max line length for which to sill emit suggestions. Used to prevent optional +# suggestions which would get split by a code formatter (e.g., black). Will +# default to the setting for ``max-line-length``. +#max-line-length-suggestions= From e3d8f57204ca199fcadfe775c3cf252601d3ef6b Mon Sep 17 00:00:00 2001 From: zyd Date: Mon, 16 May 2022 03:24:29 +0900 Subject: [PATCH 3/5] add pylint badge and pylint vscode config --- .vscode/settings.json | 7 ++++++- README.md | 2 ++ pylintrc | 3 +-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 70c4422..ddd5911 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,5 +2,10 @@ "python.formatting.autopep8Args": [ // autopep8 の設定 "--indent-size=2", "--ignore=E111, E114, E402, E501" + ], + "python.linting.pylintEnabled": true, + "python.linting.enabled": true, + "python.linting.pylintArgs": [ + "--rcfile=pylintrc" ] -} \ No newline at end of file +} diff --git a/README.md b/README.md index 31dd3d1..c479787 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ This is a repo try to copy in python. +[![linting: pylint](https://img.shields.io/badge/linting-pylint-yellowgreen)](https://github.com/PyCQA/pylint) + ## install For whom wants to use this package. diff --git a/pylintrc b/pylintrc index 5e7a619..3ef790a 100644 --- a/pylintrc +++ b/pylintrc @@ -33,7 +33,6 @@ load-plugins= pylint.extensions.code_style, pylint.extensions.overlapping_exceptions, pylint.extensions.typing, - pylint.extensions.redefined_variable_type, pylint.extensions.comparison_placement, # Use multiple processes to speed up Pylint. Specifying 0 will auto-detect the @@ -190,7 +189,7 @@ callbacks=cb_,_cb allow-global-unused-variables=yes # List of names allowed to shadow builtins -allowed-redefined-builtins= +allowed-redefined-builtins=all # Argument names that match this expression will be ignored. Default to name # with leading underscore. From c32a2793b2145c70114a032ba25b11a2088e637d Mon Sep 17 00:00:00 2001 From: zyd Date: Mon, 16 May 2022 10:03:07 +0900 Subject: [PATCH 4/5] fix by pylint --- pylintrc | 6 ++-- ramda/F.py | 2 +- ramda/Max.py | 1 + ramda/Min.py | 1 + ramda/T.py | 2 +- ramda/all.py | 2 +- ramda/always.py | 2 +- ramda/any.py | 1 + ramda/clone.py | 3 +- ramda/comparator.py | 9 +++--- ramda/difference.py | 5 ---- ramda/filter.py | 34 +++++++++++------------ ramda/indexOf.py | 3 +- ramda/keys.py | 5 ++-- ramda/lastIndexOf.py | 11 ++++---- ramda/map.py | 1 + ramda/nth.py | 9 ++++-- ramda/objOf.py | 2 +- ramda/omit.py | 11 ++++---- ramda/paths.py | 6 ++-- ramda/pick.py | 11 ++++---- ramda/pickAll.py | 17 ++++++------ ramda/private/_Set.py | 14 ++++------ ramda/private/_arity.py | 27 +++++++++--------- ramda/private/_checkForMethod.py | 3 +- ramda/private/_clone.py | 3 +- ramda/private/_concat.py | 1 + ramda/private/_curry1.py | 10 +++---- ramda/private/_curry2.py | 24 ++++++++-------- ramda/private/_curry3.py | 47 +++++++++++++++----------------- ramda/private/_curryN.py | 3 +- ramda/private/_dispatchable.py | 5 ---- ramda/private/_equals.py | 2 ++ ramda/private/_helper.py | 10 +++---- ramda/private/_identity.py | 2 +- ramda/private/_indexOf.py | 5 ++-- ramda/private/_reduce.py | 5 ++-- ramda/private/_reduced.py | 9 +++--- ramda/private/_stepCat.py | 5 ++-- ramda/private/_xReduce.py | 4 +-- ramda/private/_xReduceBy.py | 6 ++-- ramda/private/_xall.py | 4 +-- ramda/private/_xany.py | 4 +-- ramda/private/_xdrop.py | 4 +-- ramda/private/_xfBase.py | 6 +++- ramda/private/_xfilter.py | 4 +-- ramda/private/_xfind.py | 6 ++-- ramda/private/_xmap.py | 4 +-- ramda/private/_xtake.py | 7 ++--- ramda/private/_xtakeWhile.py | 9 +++--- ramda/private/_xuniqBy.py | 9 +++--- ramda/private/_xwrap.py | 2 +- ramda/range.py | 1 + ramda/slice.py | 4 +-- ramda/sortBy.py | 5 ++-- ramda/sum.py | 1 + ramda/toString.py | 4 +-- 57 files changed, 191 insertions(+), 212 deletions(-) diff --git a/pylintrc b/pylintrc index 3ef790a..53dd76a 100644 --- a/pylintrc +++ b/pylintrc @@ -13,7 +13,7 @@ ignore=CVS # Add files or directories matching the regex patterns to the ignore-list. The # regex matches against paths and can be in Posix or Windows format. -ignore-paths= +ignore-paths=test/* # Files or directories matching the regex patterns are skipped. The regex # matches against base names, not paths. @@ -189,7 +189,7 @@ callbacks=cb_,_cb allow-global-unused-variables=yes # List of names allowed to shadow builtins -allowed-redefined-builtins=all +allowed-redefined-builtins= # Argument names that match this expression will be ignored. Default to name # with leading underscore. @@ -197,7 +197,7 @@ ignored-argument-names=_.* # List of qualified module names which can have objects that can redefine # builtins. -redefining-builtins-modules=six.moves,past.builtins,future.builtins,builtins,io +redefining-builtins-modules=six.moves,past.builtins,future.builtins,builtins,io,all,any,filter,map,range,slice,sum,ramda [FORMAT] diff --git a/ramda/F.py b/ramda/F.py index 8c92e28..4f44339 100644 --- a/ramda/F.py +++ b/ramda/F.py @@ -1,2 +1,2 @@ -def F(*ignore): +def F(*_): return False diff --git a/ramda/Max.py b/ramda/Max.py index e714b83..aeabd44 100644 --- a/ramda/Max.py +++ b/ramda/Max.py @@ -6,6 +6,7 @@ def inner_max(a, b): if a == b: return b + # pylint: disable=unidiomatic-typecheck if type(a) != type(b): strA = str(a) strB = str(b) diff --git a/ramda/Min.py b/ramda/Min.py index 0533b4d..8d5862a 100644 --- a/ramda/Min.py +++ b/ramda/Min.py @@ -6,6 +6,7 @@ def inner_min(a, b): if a == b: return a + # pylint: disable=unidiomatic-typecheck if type(a) != type(b): strA = str(a) strB = str(b) diff --git a/ramda/T.py b/ramda/T.py index 23fd840..ffdc631 100644 --- a/ramda/T.py +++ b/ramda/T.py @@ -1,2 +1,2 @@ -def T(*ignore): +def T(*_): return True diff --git a/ramda/all.py b/ramda/all.py index 23e8614..10f0071 100644 --- a/ramda/all.py +++ b/ramda/all.py @@ -11,5 +11,5 @@ def inner_all(fn, arr): idx += 1 return True - +# pylint: disable=redefined-builtin all = _curry2(_dispatchable(['all'], _xall, inner_all)) diff --git a/ramda/always.py b/ramda/always.py index 0e5ecd0..7020ce0 100644 --- a/ramda/always.py +++ b/ramda/always.py @@ -2,7 +2,7 @@ def inner_always(val): - def f(*ignored): + def f(*_): return val return f diff --git a/ramda/any.py b/ramda/any.py index 50d6c49..d7d32c4 100644 --- a/ramda/any.py +++ b/ramda/any.py @@ -12,4 +12,5 @@ def inner_any(fn, arr): return False +# pylint: disable=redefined-builtin any = _curry2(_dispatchable(['any'], _xany, inner_any)) diff --git a/ramda/clone.py b/ramda/clone.py index ea31f11..8d3339f 100644 --- a/ramda/clone.py +++ b/ramda/clone.py @@ -7,8 +7,7 @@ def inner_clone(value): if _isFunction(getAttribute(value, 'clone')): return value.clone() - else: - return _clone(value, True) + return _clone(value, True) clone = _curry1(inner_clone) diff --git a/ramda/comparator.py b/ramda/comparator.py index 80b8487..d7147fd 100644 --- a/ramda/comparator.py +++ b/ramda/comparator.py @@ -2,14 +2,13 @@ def inner_comparator(pred): - def comparator(a, b): + def comparator_wrapper(a, b): if pred(a, b): return -1 - elif pred(b, a): + if pred(b, a): return 1 - else: - return 0 - return comparator + return 0 + return comparator_wrapper comparator = _curry1(inner_comparator) diff --git a/ramda/difference.py b/ramda/difference.py index 58ca5f4..79528ba 100644 --- a/ramda/difference.py +++ b/ramda/difference.py @@ -1,9 +1,4 @@ -from math import isnan - -from .equals import equals -from .find import find from .private._curry2 import _curry2 -from .private._isNumber import _isNumber from .private._Set import _Set diff --git a/ramda/filter.py b/ramda/filter.py index 710dba9..bbfc039 100644 --- a/ramda/filter.py +++ b/ramda/filter.py @@ -13,23 +13,23 @@ def inner_filter(pred, filterable): if _isArrayLike(filterable): return _filter(pred, filterable) - else: - def inner_reduce(acc, key): - """ - There are 2 cases of filterable - case 1: filterable is a dict or an instance with get method - case 2: filterable is an instance of some classes - """ - if isinstance(filterable, dict) or _has(filterable, 'get'): - if pred(filterable.get(key)): - acc[key] = filterable.get(key) - else: - # This is special, because we deepcopy the original object, - # so we delete attr from original object if not match - if not pred(getattr(filterable, key, None)): - delattr(acc, key) - return acc - return _reduce(inner_reduce, {} if isinstance(filterable, dict) or _has(filterable, 'get') else copy.deepcopy(filterable), keys(filterable)) + def inner_reduce(acc, key): + """ + There are 2 cases of filterable + case 1: filterable is a dict or an instance with get method + case 2: filterable is an instance of some classes + """ + if isinstance(filterable, dict) or _has(filterable, 'get'): + if pred(filterable.get(key)): + acc[key] = filterable.get(key) + else: + # This is special, because we deepcopy the original object, + # so we delete attr from original object if not match + if not pred(getattr(filterable, key, None)): + delattr(acc, key) + return acc + return _reduce(inner_reduce, {} if isinstance(filterable, dict) or _has(filterable, 'get') else copy.deepcopy(filterable), keys(filterable)) +# pylint: disable=redefined-builtin filter = _curry2(_dispatchable(['fantasy-land/filter', 'filter'], _xfilter, inner_filter)) diff --git a/ramda/indexOf.py b/ramda/indexOf.py index 8d7b632..4b77934 100644 --- a/ramda/indexOf.py +++ b/ramda/indexOf.py @@ -8,8 +8,7 @@ def inner_indexOf(target, xs): if _isFunction(getAttribute(xs, 'indexOf')) and not _isArray(xs): return xs.indexOf(target) - else: - return _indexOf(xs, target, 0) + return _indexOf(xs, target, 0) indexOf = _curry2(inner_indexOf) diff --git a/ramda/keys.py b/ramda/keys.py index f46d993..21a82e5 100644 --- a/ramda/keys.py +++ b/ramda/keys.py @@ -23,10 +23,9 @@ def __init__(self): """ if _has(obj, 'keys') and _isFunction(obj.keys): return list(obj.keys()) - elif _has(obj, '__dict__'): + if _has(obj, '__dict__'): return list(obj.__dict__) - else: - return [] + return [] keys = _curry1(inner_keys) diff --git a/ramda/lastIndexOf.py b/ramda/lastIndexOf.py index 7fae826..745e7aa 100644 --- a/ramda/lastIndexOf.py +++ b/ramda/lastIndexOf.py @@ -8,12 +8,11 @@ def inner_lastIndexOf(target, xs): if _isFunction(getAttribute(xs, 'lastIndexOf')) and not _isArray(xs): return xs.lastIndexOf(target) - else: - idx = len(xs) - 1 - while idx >= 0: - if equals(xs[idx], target): - return idx - idx -= 1 + idx = len(xs) - 1 + while idx >= 0: + if equals(xs[idx], target): + return idx + idx -= 1 return -1 diff --git a/ramda/map.py b/ramda/map.py index 5758aff..2385de9 100644 --- a/ramda/map.py +++ b/ramda/map.py @@ -34,4 +34,5 @@ def inner_reduce(acc, key): return _reduce(inner_reduce, {} if isinstance(functor, dict) or _has(functor, 'get') else copy.deepcopy(functor), keys(functor)) +# pylint: disable=redefined-builtin map = _curry2(_dispatchable(['fantasy-land/map', 'map'], _xmap, inner_map)) diff --git a/ramda/nth.py b/ramda/nth.py index 6804bfd..1f1dee4 100644 --- a/ramda/nth.py +++ b/ramda/nth.py @@ -5,9 +5,12 @@ def inner_nth(offset, arr): idx = len(arr) + offset if offset < 0 else offset if _isString(arr): - return arr[idx] if idx < len(arr) and idx >= 0 else '' - else: - return arr[idx] if idx < len(arr) and idx >= 0 else None + if 0 <= idx < len(arr): + return arr[idx] + return '' + if 0 <= idx < len(arr): + return arr[idx] + return None nth = _curry2(inner_nth) diff --git a/ramda/objOf.py b/ramda/objOf.py index 54b6833..87a33c2 100644 --- a/ramda/objOf.py +++ b/ramda/objOf.py @@ -1,9 +1,9 @@ from .private._curry2 import _curry2 +objOf = _curry2(lambda key, val: {key: val}) """ Since in JavaScript we can represent key-value as object, but in Python, we can't. So we treat objOf only works for dict in Python. But for the naming convention, we keep the name of objOf. """ -objOf = _curry2(lambda key, val: {key: val}) diff --git a/ramda/omit.py b/ramda/omit.py index dc66885..4386fb7 100644 --- a/ramda/omit.py +++ b/ramda/omit.py @@ -15,12 +15,11 @@ def inner_omit(names, obj): if key not in names: res[key] = obj[key] return res - else: - res = copy.copy(obj) - for key in keys(obj): - if key in names: - delattr(res, key) - return res + res = copy.copy(obj) + for key in keys(obj): + if key in names: + delattr(res, key) + return res omit = _curry2(inner_omit) diff --git a/ramda/paths.py b/ramda/paths.py index ed0a770..21f9191 100644 --- a/ramda/paths.py +++ b/ramda/paths.py @@ -6,13 +6,13 @@ def inner_paths(pathsArray, obj): - def mapWrapper(paths): + def mapWrapper(_paths): val = obj idx = 0 - while idx < len(paths): + while idx < len(_paths): if val is None: return None - p = paths[idx] + p = _paths[idx] val = nth(p, val) if _isInteger(p) else getAttribute(val, p) idx += 1 return val diff --git a/ramda/pick.py b/ramda/pick.py index 5f1d3ab..2cb0705 100644 --- a/ramda/pick.py +++ b/ramda/pick.py @@ -15,12 +15,11 @@ def inner_pick(names, obj): if name in obj: res[name] = obj[name] return res - else: - res = copy.copy(obj) - for key in keys(obj): - if key not in names: - delattr(res, key) - return res + res = copy.copy(obj) + for key in keys(obj): + if key not in names: + delattr(res, key) + return res pick = _curry2(inner_pick) diff --git a/ramda/pickAll.py b/ramda/pickAll.py index 63f6f79..033b026 100644 --- a/ramda/pickAll.py +++ b/ramda/pickAll.py @@ -17,15 +17,14 @@ def inner_pickAll(names, obj): else: res[name] = None return res - else: - res = copy.copy(obj) - for key in keys(obj): - if key not in names: - delattr(res, key) - for name in names: - if not hasattr(res, name): - setattr(res, name, None) - return res + res = copy.copy(obj) + for key in keys(obj): + if key not in names: + delattr(res, key) + for name in names: + if not hasattr(res, name): + setattr(res, name, None) + return res pickAll = _curry2(inner_pickAll) diff --git a/ramda/private/_Set.py b/ramda/private/_Set.py index 77ee7a5..bafaf98 100644 --- a/ramda/private/_Set.py +++ b/ramda/private/_Set.py @@ -1,14 +1,10 @@ -from math import isnan - -import ramda as R - -from ._isNumber import _isNumber +from ..equals import equals +from ..filter import filter class _Set(set): def add(self, item): - if R.filter(R.equals(item), list(self.__iter__())): + if filter(equals(item), list(self.__iter__())): return False - else: - super().add(item) - return True + super().add(item) + return True diff --git a/ramda/private/_arity.py b/ramda/private/_arity.py index 7cafd87..7f35a0f 100644 --- a/ramda/private/_arity.py +++ b/ramda/private/_arity.py @@ -1,20 +1,21 @@ -import ramda as R +from ..__ import __ +# pylint: disable=dangerous-default-value +# pylint: disable=keyword-arg-before-vararg def _arity(n, fn): def f0(): return fn() - def f1(a0=R.__, *____): return fn(a0, *____) - def f2(a0=R.__, a1=R.__, *____): return fn(a0, a1, *____) - def f3(a0=R.__, a1=R.__, a2=R.__, *____): return fn(a0, a1, a2, *____) - def f4(a0=R.__, a1=R.__, a2=R.__, a3=R.__, *____): return fn(a0, a1, a2, a3, *____) - def f5(a0=R.__, a1=R.__, a2=R.__, a3=R.__, a4=R.__, *____): return fn(a0, a1, a2, a3, a4, *____) - def f6(a0=R.__, a1=R.__, a2=R.__, a3=R.__, a4=R.__, a5=R.__, *____): return fn(a0, a1, a2, a3, a4, a5, *____) - def f7(a0=R.__, a1=R.__, a2=R.__, a3=R.__, a4=R.__, a5=R.__, a6=R.__, *____): return fn(a0, a1, a2, a3, a4, a5, a6, *____) - def f8(a0=R.__, a1=R.__, a2=R.__, a3=R.__, a4=R.__, a5=R.__, a6=R.__, a7=R.__, *____): return fn(a0, a1, a2, a3, a4, a5, a6, a7, *____) - def f9(a0=R.__, a1=R.__, a2=R.__, a3=R.__, a4=R.__, a5=R.__, a6=R.__, a7=R.__, a8=R.__, *____): return fn(a0, a1, a2, a3, a4, a5, a6, a7, a8, *____) - def f10(a0=R.__, a1=R.__, a2=R.__, a3=R.__, a4=R.__, a5=R.__, a6=R.__, a7=R.__, a8=R.__, a9=R.__, *____): return fn(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, *____) + def f1(a0=__, *_): return fn(a0, *_) + def f2(a0=__, a1=__, *_): return fn(a0, a1, *_) + def f3(a0=__, a1=__, a2=__, *_): return fn(a0, a1, a2, *_) + def f4(a0=__, a1=__, a2=__, a3=__, *_): return fn(a0, a1, a2, a3, *_) + def f5(a0=__, a1=__, a2=__, a3=__, a4=__, *_): return fn(a0, a1, a2, a3, a4, *_) + def f6(a0=__, a1=__, a2=__, a3=__, a4=__, a5=__, *_): return fn(a0, a1, a2, a3, a4, a5, *_) + def f7(a0=__, a1=__, a2=__, a3=__, a4=__, a5=__, a6=__, *_): return fn(a0, a1, a2, a3, a4, a5, a6, *_) + def f8(a0=__, a1=__, a2=__, a3=__, a4=__, a5=__, a6=__, a7=__, *_): return fn(a0, a1, a2, a3, a4, a5, a6, a7, *_) + def f9(a0=__, a1=__, a2=__, a3=__, a4=__, a5=__, a6=__, a7=__, a8=__, *_): return fn(a0, a1, a2, a3, a4, a5, a6, a7, a8, *_) + def f10(a0=__, a1=__, a2=__, a3=__, a4=__, a5=__, a6=__, a7=__, a8=__, a9=__, *_): return fn(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, *_) m = {0: f0, 1: f1, 2: f2, 3: f3, 4: f4, 5: f5, 6: f6, 7: f7, 8: f8, 9: f9, 10: f10} if n in m: return m[n] - else: - raise Exception('First argument to _arity must be a non-negative integer no greater than ten') + raise Exception('First argument to _arity must be a non-negative integer no greater than ten') diff --git a/ramda/private/_checkForMethod.py b/ramda/private/_checkForMethod.py index d3f1205..71b80ee 100644 --- a/ramda/private/_checkForMethod.py +++ b/ramda/private/_checkForMethod.py @@ -10,6 +10,5 @@ def wrapper(*arguments): obj = arguments[-1] if _isArray(obj) or not _isFunction(getAttribute(obj, methodName)): return fn(*arguments) - else: - return getAttribute(obj, methodName)(*arguments[:-1]) + return getAttribute(obj, methodName)(*arguments[:-1]) return wrapper diff --git a/ramda/private/_clone.py b/ramda/private/_clone.py index 82ab0bc..df7d63e 100644 --- a/ramda/private/_clone.py +++ b/ramda/private/_clone.py @@ -7,5 +7,4 @@ def _clone(value, deep=True): """ if deep: return copy.deepcopy(value) - else: - return copy.copy(value) + return copy.copy(value) diff --git a/ramda/private/_concat.py b/ramda/private/_concat.py index 7151c61..3f84d9e 100644 --- a/ramda/private/_concat.py +++ b/ramda/private/_concat.py @@ -1,2 +1,3 @@ +# pylint: disable=dangerous-default-value def _concat(set1 = [], set2 = []): return set1 + set2 diff --git a/ramda/private/_curry1.py b/ramda/private/_curry1.py index a445fa3..4a3f7eb 100644 --- a/ramda/private/_curry1.py +++ b/ramda/private/_curry1.py @@ -1,12 +1,12 @@ -import ramda as R - +from ..__ import __ from ._isPlaceholder import _isPlaceholder def _curry1(fn): - def f1(a = R.__, *ignored): + # pylint: disable=dangerous-default-value + # pylint: disable=keyword-arg-before-vararg + def f1(a=__, *_): if _isPlaceholder(a): return f1 - else: - return fn(a) + return fn(a) return f1 diff --git a/ramda/private/_curry2.py b/ramda/private/_curry2.py index 9449bb7..53b6220 100644 --- a/ramda/private/_curry2.py +++ b/ramda/private/_curry2.py @@ -4,24 +4,22 @@ def _curry2(fn): def f2(*args): + def f_b(_b): return fn(args[0], _b) if len(args) == 0: return f2 - elif len(args) == 1: + if len(args) == 1: a = args[0] if _isPlaceholder(a): return f2 - def f_b(_b): return fn(args[0], _b) return _curry1(f_b) - else: - a, b = args[0], args[1] - if _isPlaceholder(a) and _isPlaceholder(b): - return f2 - elif _isPlaceholder(a): - def f_a(_a): return fn(_a, b) - return _curry1(f_a) - elif _isPlaceholder(b): - def f_b(_b): return fn(a, _b) - return _curry1(f_b) - return fn(a, b) + a, b = args[0], args[1] + if _isPlaceholder(a) and _isPlaceholder(b): + return f2 + if _isPlaceholder(a): + def f_a(_a): return fn(_a, b) + return _curry1(f_a) + if _isPlaceholder(b): + return _curry1(f_b) + return fn(a, b) return f2 diff --git a/ramda/private/_curry3.py b/ramda/private/_curry3.py index b720e6f..cb7026b 100644 --- a/ramda/private/_curry3.py +++ b/ramda/private/_curry3.py @@ -4,6 +4,7 @@ def _curry3(fn): + # pylint: disable=too-many-return-statements def f3(*args): if len(args) >= 1: a = args[0] @@ -20,35 +21,31 @@ def f_b(_b): return fn(a, _b, c) def f_c(_c): return fn(a, b, _c) if len(args) == 0: return f3 - elif len(args) == 1: + if len(args) == 1: if _isPlaceholder(a): return f3 - else: - return _curry2(f_bc) - elif len(args) == 2: + return _curry2(f_bc) + if len(args) == 2: if _isPlaceholder(a) and _isPlaceholder(b): return f3 - elif _isPlaceholder(a): - return _curry2(f_ac) - elif _isPlaceholder(b): - return _curry2(f_bc) - else: - return _curry1(f_c) - else: - if _isPlaceholder(a) and _isPlaceholder(b) and _isPlaceholder(c): - return f3 - elif _isPlaceholder(a) and _isPlaceholder(b): - return _curry2(f_ab) - elif _isPlaceholder(a) and _isPlaceholder(c): + if _isPlaceholder(a): return _curry2(f_ac) - elif _isPlaceholder(b) and _isPlaceholder(c): + if _isPlaceholder(b): return _curry2(f_bc) - elif _isPlaceholder(a): - return _curry1(f_a) - elif _isPlaceholder(b): - return _curry1(f_b) - elif _isPlaceholder(c): - return _curry1(f_c) - else: - return fn(a, b, c) + return _curry1(f_c) + if _isPlaceholder(a) and _isPlaceholder(b) and _isPlaceholder(c): + return f3 + if _isPlaceholder(a) and _isPlaceholder(b): + return _curry2(f_ab) + if _isPlaceholder(a) and _isPlaceholder(c): + return _curry2(f_ac) + if _isPlaceholder(b) and _isPlaceholder(c): + return _curry2(f_bc) + if _isPlaceholder(a): + return _curry1(f_a) + if _isPlaceholder(b): + return _curry1(f_b) + if _isPlaceholder(c): + return _curry1(f_c) + return fn(a, b, c) return f3 diff --git a/ramda/private/_curryN.py b/ramda/private/_curryN.py index a25c1f1..d778dbb 100644 --- a/ramda/private/_curryN.py +++ b/ramda/private/_curryN.py @@ -21,6 +21,5 @@ def f1(*arguments): combinedIdx += 1 if left <= 0: return fn(*combined) - else: - return _arity(left, _curryN(n, combined, fn)) + return _arity(left, _curryN(n, combined, fn)) return f1 diff --git a/ramda/private/_dispatchable.py b/ramda/private/_dispatchable.py index 16cf350..27e1add 100644 --- a/ramda/private/_dispatchable.py +++ b/ramda/private/_dispatchable.py @@ -12,11 +12,6 @@ def f(*arguments): if not _isArray(obj): idx = 0 while idx < len(methodNames): - """ - There are 2 cases - case1: obj is an instance of some class, that instance has method with given name - case2: obj is a dict or an instance with get method - """ method = getAttribute(obj, methodNames[idx]) if _isFunction(method): return method(*arguments[:-1]) diff --git a/ramda/private/_equals.py b/ramda/private/_equals.py index a825deb..d9e048e 100644 --- a/ramda/private/_equals.py +++ b/ramda/private/_equals.py @@ -9,6 +9,7 @@ def _equals(a, b): if _isNumber(a) and isnan(a) and _isNumber(b) and isnan(b): return True + # pylint: disable=unidiomatic-typecheck if type(a) != type(b): return False if isinstance(a, BaseException): @@ -18,6 +19,7 @@ def _equals(a, b): # Array-like if len(a) != len(b): return False + # pylint: disable=consider-using-enumerate for i in range(len(a)): if not _equals(a[i], b[i]): return False diff --git a/ramda/private/_helper.py b/ramda/private/_helper.py index 4c7aa6b..01ed7bd 100644 --- a/ramda/private/_helper.py +++ b/ramda/private/_helper.py @@ -15,17 +15,18 @@ def toNumber(a): Convert any input a to a number type if can not convert, then return nan """ - if isinstance(a, float) or isinstance(a, int): + if isinstance(a, (int, float)): return a try: return int(a) - except: + except (ValueError, TypeError): try: return float(a) - except: + except (ValueError, TypeError): return float('nan') +# pylint: disable=inconsistent-return-statements def getAttribute(v, key): """ This function is mainly for retrive @@transducer/xxx property, and fantasy-land/xxx property. @@ -69,5 +70,4 @@ def map(fn): def safeLen(x): if _isArrayLike(x): return len(x) - else: - return 0 + return 0 diff --git a/ramda/private/_identity.py b/ramda/private/_identity.py index 6615f7c..ff46d27 100644 --- a/ramda/private/_identity.py +++ b/ramda/private/_identity.py @@ -1,2 +1,2 @@ -def _identity(x, *ignore): +def _identity(x, *_): return x diff --git a/ramda/private/_indexOf.py b/ramda/private/_indexOf.py index a233dda..454a490 100644 --- a/ramda/private/_indexOf.py +++ b/ramda/private/_indexOf.py @@ -1,7 +1,6 @@ from math import isnan -import ramda as R - +from ..equals import equals from ._helper import getAttribute from ._isFunction import _isFunction from ._isNumber import _isNumber @@ -17,7 +16,7 @@ def _indexOf(arr, a, idx): return arr.indexOf(a, idx) while idx < len(arr): - if R.equals(arr[idx], a): + if equals(arr[idx], a): return idx idx += 1 return -1 diff --git a/ramda/private/_reduce.py b/ramda/private/_reduce.py index d05f24c..bc45fd1 100644 --- a/ramda/private/_reduce.py +++ b/ramda/private/_reduce.py @@ -1,14 +1,13 @@ from ._arrayReduce import _arrayReduce from ._createReduce import _createReduce from ._helper import getAttribute -from ._xwrap import _xwrap -def _iterableReduce(reducer, acc, iter): +def _iterableReduce(reducer, acc, _iter): while True: try: - value = next(iter) + value = next(_iter) acc = reducer(acc, value) except StopIteration: break diff --git a/ramda/private/_reduced.py b/ramda/private/_reduced.py index a507480..e0f95d1 100644 --- a/ramda/private/_reduced.py +++ b/ramda/private/_reduced.py @@ -4,8 +4,7 @@ def _reduced(x): if getAttribute(x, '@@transducer/reduced'): return x - else: - return { - '@@transducer/value': x, - '@@transducer/reduced': True - } + return { + '@@transducer/value': x, + '@@transducer/reduced': True + } diff --git a/ramda/private/_stepCat.py b/ramda/private/_stepCat.py index 2e2f637..ea05336 100644 --- a/ramda/private/_stepCat.py +++ b/ramda/private/_stepCat.py @@ -1,5 +1,4 @@ -import ramda as R - +from ..objOf import objOf from ._identity import _identity from ._isArrayLike import _isArrayLike from ._isTransformer import _isTransformer @@ -23,7 +22,7 @@ def _array_step(xs, x): _stepCatDict = { '@@transducer/init': dict, # use Python 3.9 feature - '@@transducer/step': lambda result, input: result | (R.objOf(input[0], input[1]) if _isArrayLike(input) else input), + '@@transducer/step': lambda result, input: result | (objOf(input[0], input[1]) if _isArrayLike(input) else input), '@@transducer/result': _identity } diff --git a/ramda/private/_xReduce.py b/ramda/private/_xReduce.py index 37967d1..c7fa501 100644 --- a/ramda/private/_xReduce.py +++ b/ramda/private/_xReduce.py @@ -3,10 +3,10 @@ from ._xArrayReduce import _xArrayReduce -def _xIterableReduce(xf, acc, iter): +def _xIterableReduce(xf, acc, _iter): while True: try: - acc = getAttribute(xf, '@@transducer/step')(acc, next(iter)) + acc = getAttribute(xf, '@@transducer/step')(acc, next(_iter)) if acc and getAttribute(acc, '@@transducer/reduced'): acc = getAttribute(acc, '@@transducer/value') break diff --git a/ramda/private/_xReduceBy.py b/ramda/private/_xReduceBy.py index df70592..38d2729 100644 --- a/ramda/private/_xReduceBy.py +++ b/ramda/private/_xReduceBy.py @@ -22,10 +22,10 @@ def result(self, result): self.inputs = None return getAttribute(self.xf, '@@transducer/result')(result) - def step(self, result, input): - key = self.keyFn(input) + def step(self, result, _input): + key = self.keyFn(_input) self.inputs[key] = getAttribute(self.inputs, key) or [key, _clone(self.valueAcc, deep=False)] - self.inputs[key][1] = self.valueFn(self.inputs[key][1], input) + self.inputs[key][1] = self.valueFn(self.inputs[key][1], _input) return result diff --git a/ramda/private/_xall.py b/ramda/private/_xall.py index c136724..f5a9dd7 100644 --- a/ramda/private/_xall.py +++ b/ramda/private/_xall.py @@ -14,8 +14,8 @@ def result(self, result): result = getAttribute(self.xf, '@@transducer/step')(result, True) return self.xf.get('@@transducer/result')(result) - def step(self, result, input): - if not self.f(input): + def step(self, result, _input): + if not self.f(_input): self.all = False result = _reduced(getAttribute(self.xf, '@@transducer/step')(result, False)) return result diff --git a/ramda/private/_xany.py b/ramda/private/_xany.py index 2bed009..58517c0 100644 --- a/ramda/private/_xany.py +++ b/ramda/private/_xany.py @@ -14,8 +14,8 @@ def result(self, result): result = getAttribute(self.xf, '@@transducer/step')(result, False) return self.xf.get('@@transducer/result')(result) - def step(self, result, input): - if self.f(input): + def step(self, result, _input): + if self.f(_input): self.any = True result = _reduced(getAttribute(self.xf, '@@transducer/step')(result, True)) return result diff --git a/ramda/private/_xdrop.py b/ramda/private/_xdrop.py index e52b729..9e5fe33 100644 --- a/ramda/private/_xdrop.py +++ b/ramda/private/_xdrop.py @@ -7,11 +7,11 @@ def __init__(self, n, xf): self.xf = xf self.n = n - def step(self, result, input): + def step(self, result, _input): if self.n > 0: self.n -= 1 return result - return getAttribute(self.xf, '@@transducer/step')(result, input) + return getAttribute(self.xf, '@@transducer/step')(result, _input) def _xdrop(n): return lambda xf: XDrop(n, xf) diff --git a/ramda/private/_xfBase.py b/ramda/private/_xfBase.py index 4a999c1..a3689ed 100644 --- a/ramda/private/_xfBase.py +++ b/ramda/private/_xfBase.py @@ -7,13 +7,17 @@ class XfBase: For extracting the common part to deal with transducer related logic. """ + def _init_(self, xf): + self.xf = xf + def init(self): return getAttribute(self.xf, '@@transducer/init')() def result(self, result): return getAttribute(self.xf, '@@transducer/result')(result) - def step(self, result, input): + # pylint: disable=no-self-use + def step(self, result, _input): raise Exception('Child class should implement this') def get(self, name, default=None): diff --git a/ramda/private/_xfilter.py b/ramda/private/_xfilter.py index d07eb5f..8d3e4c1 100644 --- a/ramda/private/_xfilter.py +++ b/ramda/private/_xfilter.py @@ -7,7 +7,7 @@ def __init__(self, f, xf): self.xf = xf self.f = f - def step(self, result, input): - return getAttribute(self.xf, '@@transducer/step')(result, input) if self.f(input) else result + def step(self, result, _input): + return getAttribute(self.xf, '@@transducer/step')(result, _input) if self.f(_input) else result def _xfilter(f): return lambda xf: XFilter(f, xf) diff --git a/ramda/private/_xfind.py b/ramda/private/_xfind.py index b8d0b48..0580cec 100644 --- a/ramda/private/_xfind.py +++ b/ramda/private/_xfind.py @@ -14,10 +14,10 @@ def result(self, result): result = getAttribute(self.xf, '@@transducer/step')(result, None) return self.xf.get('@@transducer/result')(result) - def step(self, result, input): - if self.f(input): + def step(self, result, _input): + if self.f(_input): self.found = True - result = _reduced(getAttribute(self.xf, '@@transducer/step')(result, input)) + result = _reduced(getAttribute(self.xf, '@@transducer/step')(result, _input)) return result diff --git a/ramda/private/_xmap.py b/ramda/private/_xmap.py index 155286b..7327fdb 100644 --- a/ramda/private/_xmap.py +++ b/ramda/private/_xmap.py @@ -7,8 +7,8 @@ def __init__(self, f, xf): self.xf = xf self.f = f - def step(self, result, input): - return getAttribute(self.xf, '@@transducer/step')(result, self.f(input)) + def step(self, result, _input): + return getAttribute(self.xf, '@@transducer/step')(result, self.f(_input)) def _xmap(f): return lambda xf: XMap(f, xf) diff --git a/ramda/private/_xtake.py b/ramda/private/_xtake.py index fabb173..969aab5 100644 --- a/ramda/private/_xtake.py +++ b/ramda/private/_xtake.py @@ -9,13 +9,12 @@ def __init__(self, n, xf): self.n = n self.i = 0 - def step(self, result, input): + def step(self, result, _input): self.i += 1 - ret = result if self.n == 0 else getAttribute(self.xf, '@@transducer/step')(result, input) + ret = result if self.n == 0 else getAttribute(self.xf, '@@transducer/step')(result, _input) if self.n >= 0 and self.i >= self.n: return _reduced(ret) - else: - return ret + return ret def _xtake(n): return lambda xf: XTake(n, xf) diff --git a/ramda/private/_xtakeWhile.py b/ramda/private/_xtakeWhile.py index 1218b8f..822120b 100644 --- a/ramda/private/_xtakeWhile.py +++ b/ramda/private/_xtakeWhile.py @@ -8,11 +8,10 @@ def __init__(self, f, xf): self.xf = xf self.f = f - def step(self, result, input): - if self.f(input): - return getAttribute(self.xf, '@@transducer/step')(result, input) - else: - return _reduced(result) + def step(self, result, _input): + if self.f(_input): + return getAttribute(self.xf, '@@transducer/step')(result, _input) + return _reduced(result) def _xtakeWhile(f): return lambda xf: XTakeWhile(f, xf) diff --git a/ramda/private/_xuniqBy.py b/ramda/private/_xuniqBy.py index fa57eaa..e0d00d3 100644 --- a/ramda/private/_xuniqBy.py +++ b/ramda/private/_xuniqBy.py @@ -9,11 +9,10 @@ def __init__(self, f, xf): self.f = f self._set = _Set() - def step(self, result, input): - if self._set.add(self.f(input)): - return getAttribute(self.xf, '@@transducer/step')(result, input) - else: - return result + def step(self, result, _input): + if self._set.add(self.f(_input)): + return getAttribute(self.xf, '@@transducer/step')(result, _input) + return result def _xuniqBy(f): return lambda xf: XUniqBy(f, xf) diff --git a/ramda/private/_xwrap.py b/ramda/private/_xwrap.py index b564db7..b2a363f 100644 --- a/ramda/private/_xwrap.py +++ b/ramda/private/_xwrap.py @@ -6,5 +6,5 @@ def _xwrap(fn): return { '@@transducer/init': transducer_init, '@@transducer/result': lambda acc: acc, - '@@transducer/step': lambda acc, x: fn(acc, x) + '@@transducer/step': fn } diff --git a/ramda/range.py b/ramda/range.py index 5061997..b755b1e 100644 --- a/ramda/range.py +++ b/ramda/range.py @@ -13,4 +13,5 @@ def inner_range(frm, to): return result +# pylint: disable=redefined-builtin range = _curry2(inner_range) diff --git a/ramda/slice.py b/ramda/slice.py index 42d0f82..850e308 100644 --- a/ramda/slice.py +++ b/ramda/slice.py @@ -5,8 +5,8 @@ def inner_slice(fromIndex, toIndex, arr): if toIndex is None: return arr[fromIndex:] - else: - return arr[fromIndex:toIndex] + return arr[fromIndex:toIndex] +# pylint: disable=redefined-builtin slice = _curry3(_checkForMethod('slice', inner_slice)) diff --git a/ramda/sortBy.py b/ramda/sortBy.py index 398291f..7bded43 100644 --- a/ramda/sortBy.py +++ b/ramda/sortBy.py @@ -9,10 +9,9 @@ def comparator(a, b): bb = fn(b) if aa < bb: return -1 - elif aa > bb: + if aa > bb: return 1 - else: - return 0 + return 0 return sorted(arr, key=cmp_to_key(comparator)) diff --git a/ramda/sum.py b/ramda/sum.py index 44f2560..3b352ec 100644 --- a/ramda/sum.py +++ b/ramda/sum.py @@ -1,4 +1,5 @@ from .add import add from .reduce import reduce +# pylint: disable=redefined-builtin sum = reduce(add, 0) diff --git a/ramda/toString.py b/ramda/toString.py index cf5c9cb..dfb34f6 100644 --- a/ramda/toString.py +++ b/ramda/toString.py @@ -4,12 +4,12 @@ def inner_toString(val): - if _isString(val): - return _quote(val) """ TODO: dict, set, list, tuple, function, object TODO: regex, date if needed """ + if _isString(val): + return _quote(val) return str(val) From 829ceab054c55e0558908afbb44d2e8eac1d542f Mon Sep 17 00:00:00 2001 From: zyd Date: Mon, 16 May 2022 10:19:10 +0900 Subject: [PATCH 5/5] modify vscode --- .vscode/settings.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index ddd5911..c5f64d2 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,9 +1,10 @@ { - "python.formatting.autopep8Args": [ // autopep8 の設定 + "python.formatting.autopep8Args": [ "--indent-size=2", "--ignore=E111, E114, E402, E501" ], "python.linting.pylintEnabled": true, + "python.linting.cwd": "{workspaceFolder}/ramda", "python.linting.enabled": true, "python.linting.pylintArgs": [ "--rcfile=pylintrc"