instance_id
stringlengths
10
57
file_changes
listlengths
1
15
repo
stringlengths
7
53
base_commit
stringlengths
40
40
problem_statement
stringlengths
11
52.5k
patch
stringlengths
251
7.06M
asottile__add-trailing-comma-85
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "add_trailing_comma.py:fix_file", "add_trailing_comma.py:main" ], "edited_modules": [ "add_trailing_comma.py:fix_file", "add_trailing_comma.py:main" ] }, ...
asottile/add-trailing-comma
64047876fad76230949d4fe8903a29323aaf1911
Even if successful, add-trailing-comma reading from stdin returns 1 as a status code in the shell. Is this the intended behavior? Create a `test.py`: ```python # -*- coding: utf-8 -*- test = [ 1, 2 ] ``` `add-trailing-comma - < test.py` outputs correctly: ```python # -*- coding: utf-8 -*- t...
diff --git a/add_trailing_comma.py b/add_trailing_comma.py index 7052979..ea579a6 100644 --- a/add_trailing_comma.py +++ b/add_trailing_comma.py @@ -517,13 +517,17 @@ def fix_file(filename, args): with io.open(filename, 'w', newline='', encoding='UTF-8') as f: f.write(contents_text) - return ...
asottile__all-repos-105
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "all_repos/clone.py:_fetch_reset", "all_repos/clone.py:main" ], "edited_modules": [ "all_repos/clone.py:_fetch_reset", "all_repos/clone.py:main" ] }, "fi...
asottile/all-repos
f1ddeecf135d238424e3816876688fdb8ee349f8
remote branches After running the `all-repos-clone` command, I am not able to checkout any remote branches for the cloned repositories. I have tried running `git fetch --all` though that does not do anything. _(discussed briefly on stream)_
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f0780b3..c70c996 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v2.1.0 + rev: v2.2.3 hooks: - id: trailing-whitespace -...
asottile__all-repos-22
[ { "changes": { "added_entities": [ "all_repos/autofix_lib.py:_interactive_check" ], "added_modules": [ "all_repos/autofix_lib.py:_interactive_check" ], "edited_entities": [ "all_repos/autofix_lib.py:AutofixSettings.from_cli", "all_repos/autofix_lib.p...
asottile/all-repos
5c980cde22d85a79eec64f25fb0e31ffa0990c16
autofix_lib: --interactive Add an interactive mode for autofixers which utilize `autofix_lib`
diff --git a/all_repos/autofix_lib.py b/all_repos/autofix_lib.py index 8407bee..8b2372e 100644 --- a/all_repos/autofix_lib.py +++ b/all_repos/autofix_lib.py @@ -27,7 +27,8 @@ class Commit(collections.namedtuple( class AutofixSettings(collections.namedtuple( - 'AutofixSettings', ('jobs', 'color', 'limit', 'd...
asottile__all-repos-322
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "all_repos/push/azure_repos_pull_request.py:make_pull_request" ], "edited_modules": [ "all_repos/push/azure_repos_pull_request.py:Settings", "all_repos/push/azure_repos_pull_r...
asottile/all-repos
96c25dcfb9be6f2fc21625df1c723282e1cc80a3
Support creating draft PRs for AzDO Hey, I successfully configured the tool to run with Azure DevOps, but I noticed that config included in the repo always causes creating standard PRs. In my organization, a standard PR automatically triggers CI, so it creates high queues for CI agents when a lot of PRs are created. ...
diff --git a/all_repos/push/azure_repos_pull_request.py b/all_repos/push/azure_repos_pull_request.py index 4d1e075..58d71e8 100644 --- a/all_repos/push/azure_repos_pull_request.py +++ b/all_repos/push/azure_repos_pull_request.py @@ -19,6 +19,7 @@ class Settings(NamedTuple): base_url: str = 'https://dev.azure.com' ...
asottile__all-repos-91
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "all_repos/github_api.py:filter_repos" ], "edited_modules": [ "all_repos/github_api.py:filter_repos" ] }, "file": "all_repos/github_api.py" }, { "changes": { ...
asottile/all-repos
27aba1dda4e69ae598f8e676006c86c61eab5559
github, github_org: don't clone archived repos by default and have an `archived: true` option for enabling them
diff --git a/all_repos/github_api.py b/all_repos/github_api.py index c35a60c..066b1f2 100644 --- a/all_repos/github_api.py +++ b/all_repos/github_api.py @@ -49,7 +49,7 @@ def get_all(url: str, **kwargs: Any) -> List[Dict[str, Any]]: def filter_repos( repos: List[Dict[str, Any]], *, - forks: bool, pri...
asottile__all-repos-95
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "all_repos/list_repos.py:main" ], "edited_modules": [ "all_repos/list_repos.py:main" ] }, "file": "all_repos/list_repos.py" } ]
asottile/all-repos
e1d19b3cd27645e16d87be83afa81dd70b83096e
`all-repos-list-repos`: add `--output-paths` The current output is a little clunky when trying to chain with xargs: ```console $ all-repos-list-repos | tail -5 Yelp/docker-push-latest-if-changed Yelp/requirements-tools Yelp/venv-update Yelp/wsgi-mod-rpaf Yelp/yelp_cheetah ``` For instance: ```console $...
diff --git a/all_repos/list_repos.py b/all_repos/list_repos.py index 470c4f7..f365192 100644 --- a/all_repos/list_repos.py +++ b/all_repos/list_repos.py @@ -1,4 +1,5 @@ import argparse +import os from typing import Optional from typing import Sequence @@ -12,11 +13,15 @@ def main(argv: Optional[Sequence[str]] = No...
asottile__astpretty-41
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "astpretty.py:pformat" ], "edited_modules": [ "astpretty.py:pformat" ] }, "file": "astpretty.py" } ]
asottile/astpretty
42ec5bd247e0b84bdbb556459d7d428bb8f34369
Have an option for indent argument to be number of spaces Like `json.dumps` or `ast.dump`, making indent have an option to be an integer would be nice. I could probably make a PR for this, if the idea gets approval.
diff --git a/astpretty.py b/astpretty.py index d0c1b59..abc8444 100644 --- a/astpretty.py +++ b/astpretty.py @@ -75,7 +75,7 @@ def _leaf(node: 'ASTType', show_offsets: bool = True) -> str: def pformat( node: Union['ASTType', None, str], - indent: str = ' ', + indent: Union[str, int] = ' ...
asottile__babi-122
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "babi/file.py:File.backspace" ], "edited_modules": [ "babi/file.py:File" ] }, "file": "babi/file.py" } ]
asottile/babi
8245ee56a506a8d853339b5ad9ca6d4b9c6b6561
backspacing blank line at end of file doesn't work - `echo -en 'foo\n\n' > t` - `babi t` - <kbd>ctrl+end</kbd> - <kbd>backspace</kbd> - <kbd>ctrl+s</kbd> - <kbd>ctrl+x</kbd> (close babi) - `babi t` (reopen the file) - the extra blank line is still there this used to work, hmmm
diff --git a/babi/file.py b/babi/file.py index fd99b74..0a3d05c 100644 --- a/babi/file.py +++ b/babi/file.py @@ -476,7 +476,11 @@ class File: if self.buf.y == 0 and self.buf.x == 0: pass # backspace at the end of the file does not change the contents - elif self.buf.y == len(self.b...
asottile__babi-164
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "babi/screen.py:Screen.replace" ], "edited_modules": [ "babi/screen.py:Screen" ] }, "file": "babi/screen.py" } ]
asottile/babi
d7ffdd1db821c3952f698d087dfdab053eade816
regex replace invalid replace causes crash ``` $ nano babi/file.py Traceback (most recent call last): File "/home/asottile/bin/nano", line 8, in <module> sys.exit(main()) File "/home/asottile/opt/venv/lib/python3.6/site-packages/babi/main.py", line 108, in main return c_main(stdscr, args, stdin) F...
diff --git a/babi/screen.py b/babi/screen.py index 9d725d4..c86bc71 100644 --- a/babi/screen.py +++ b/babi/screen.py @@ -7,6 +7,7 @@ import hashlib import os import re import signal +import sre_parse import sys from typing import Generator from typing import NamedTuple @@ -419,7 +420,12 @@ class Screen: ...
asottile__babi-179
[ { "changes": { "added_entities": [ "babi/file.py:File.alt_up", "babi/file.py:File.alt_down" ], "added_modules": null, "edited_entities": null, "edited_modules": [ "babi/file.py:File" ] }, "file": "babi/file.py" } ]
asottile/babi
c8fd9571dcc012e219cb3dbbc1dd4af4b2c33230
Jump to paragraph - feature request Hello. Is there a possibility that you can add a **jump to paragraph** feature, like in nano? This is what I mean: ![nano presentation](https://i.imgur.com/as6lXWT.gif) I achieve this by pressing <kbd>Ctrl</kbd> + <kbd>Arrow Up</kbd>/<kbd>Arrow Down</kbd> and I don't see this feat...
diff --git a/babi/file.py b/babi/file.py index 0f3e9f2..9f618a3 100644 --- a/babi/file.py +++ b/babi/file.py @@ -465,6 +465,45 @@ class File: self.buf.y = self.buf.file_y = pos self.buf.x = 0 + @action + def alt_up(self, margin: Margin) -> None: + if self.buf.y > 0: + off...
asottile__babi-181
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "babi/screen.py:Screen.save" ], "edited_modules": [ "babi/screen.py:Screen" ] }, "file": "babi/screen.py" } ]
asottile/babi
961f9d0dfd4dc6c097572c4eed3c41398e67d2c3
TODO: make directories if they don't exist This issue is equivalent to the comment in `babi/screen.py` at line 490. I would like to work on this to resolve the TODO-comment.
diff --git a/babi/screen.py b/babi/screen.py index bca6656..80c6d7a 100644 --- a/babi/screen.py +++ b/babi/screen.py @@ -487,7 +487,6 @@ class Screen: def save(self) -> PromptResult | None: self.file.finalize_previous_action() - # TODO: make directories if they don't exist # TODO: maybe ...
asottile__babi-187
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "babi/buf.py:Buf.clear_callbacks" ], "edited_modules": [ "babi/buf.py:Buf" ] }, "file": "babi/buf.py" }, { "changes": { "added_entities": null, "adde...
asottile/babi
e137233f4d79614f5b9d2cd5f6021a19a02fdde8
utilize identify's shebang detection for grammar when possible an example: ```python #!/usr/bin/env python3 print('hello') ``` this file saved as `foo/install` gets highlighted incorrectly as shell, but we can utilize `tags_from_path` to identify this as `python` earlier on
diff --git a/babi/buf.py b/babi/buf.py index 01b385f..0b03d45 100644 --- a/babi/buf.py +++ b/babi/buf.py @@ -179,11 +179,6 @@ class Buf: def remove_ins_callback(self, cb: InsCallback) -> None: self._ins_callbacks.remove(cb) - def clear_callbacks(self) -> None: - self._set_callbacks[:] = [self....
asottile__babi-220
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "babi/file.py:File.alt_up" ], "edited_modules": [ "babi/file.py:File" ] }, "file": "babi/file.py" } ]
asottile/babi
079e2109843d6fbdd02ef997f0315b97a0e47a9c
Alt-UP crashes if the first line in the buffer is empty To reproduce: - open babi - press enter - press Alt-UP This happens because there is no bound check in Alt-UP action implementation when counting the offset. I can issue a pull request with slightly different implementation where the bound check is obviou...
diff --git a/README.md b/README.md index d954f11..edd28f2 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ these are all of the current key bindings in babi - <kbd>^V</kbd> / <kbd>pagedown</kbd>: move down one page - <kbd>^-left</kbd> / <kbd>^-right</kbd>: jump by word - <kbd>^-home</kbd> / <kbd>^-end</kbd>:...
asottile__babi-247
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "babi/file.py:_SearchIter.__next__" ], "edited_modules": [ "babi/file.py:_SearchIter" ] }, "file": "babi/file.py" } ]
asottile/babi
6d9106cdf9a50d76bfeec1f90998716bc32f20da
regex replace can break EOF invariant for example, do a replace with `^` => ` ` and replace all and the end of the file will be forever broken-ish
diff --git a/babi/file.py b/babi/file.py index 57b707e..73182d3 100644 --- a/babi/file.py +++ b/babi/file.py @@ -195,7 +195,7 @@ class _SearchIter: if match: return self._stop_if_past_original(line_y, match) else: - for line_y in range(y + 1, len(self.file.buf))...
asottile__babi-311
[ { "changes": { "added_entities": null, "added_modules": [ "babi/file.py:NullByteError" ], "edited_entities": [ "babi/file.py:get_lines", "babi/file.py:_load_file" ], "edited_modules": [ "babi/file.py:get_lines", "babi/file.py:_load_file...
asottile/babi
6f5b99ef679e756bf6fba74e03b41850ee2780c3
file containing null byte causes crash ### reproduction ```bash echo -e '\x00' > bytes.txt && babi bytes.txt ``` Traceback: ```console Traceback (most recent call last): File "/tmp/venv/bin/babi", line 8, in <module> sys.exit(main()) File "/tmp/venv/lib/python3.10/site-packages/babi/main.py", line 176,...
diff --git a/babi/file.py b/babi/file.py index 73182d3..3fa5184 100644 --- a/babi/file.py +++ b/babi/file.py @@ -40,11 +40,17 @@ TCallable = TypeVar('TCallable', bound=Callable[..., Any]) WS_RE = re.compile(r'^\s*') +class NullByteError(ValueError): + pass + + def get_lines(sio: IO[str]) -> tuple[list[str], st...
asottile__babi-312
[ { "changes": { "added_entities": null, "added_modules": [ "babi/file.py:OpenSettings" ], "edited_entities": null, "edited_modules": null }, "file": "babi/file.py" }, { "changes": { "added_entities": null, "added_modules": null, "edited_enti...
asottile/babi
f1fb34e33e11e4185118568b359b6b22563ad739
saving over a non-utf-8 file causes a crash I typed `hello world`, then <kbd>^O</kbd>, then `f`, then <kbd>Enter</kbd> ```console $ echo $'\x98\xea\xf2' > f $ babi Traceback (most recent call last): File "/home/asottile/bin/babi", line 8, in <module> sys.exit(main()) File "/home/asottile/opt/venv/lib/p...
diff --git a/babi/file.py b/babi/file.py index 3fa5184..7a0d353 100644 --- a/babi/file.py +++ b/babi/file.py @@ -14,10 +14,12 @@ from typing import Callable from typing import cast from typing import Generator from typing import IO +from typing import Literal from typing import Match from typing import NamedTuple ...
asottile__babi-328
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "babi/linters/pre_commit.py:PreCommit.command" ], "edited_modules": [ "babi/linters/pre_commit.py:PreCommit" ] }, "file": "babi/linters/pre_commit.py" } ]
asottile/babi
4d4b0ef970286374a33d886b0695ed6c92409325
pre-commit runs with the wrong configuration when accessing a file in a different repository went through all the trouble to check the right config exists here: https://github.com/asottile/babi/blob/5cf5f2501c90274e7f640ff0ad4dfb355631b960/babi/linters/pre_commit.py#L66 but then didn't bother actually using it here:...
diff --git a/babi/linters/pre_commit.py b/babi/linters/pre_commit.py index d5ffc5c..380608b 100644 --- a/babi/linters/pre_commit.py +++ b/babi/linters/pre_commit.py @@ -63,10 +63,16 @@ class PreCommit: return None # not in a git repo! # no pre-commit config! - if not os.path.exists(os.pa...
asottile__babi-350
[ { "changes": { "added_entities": [ "babi/file.py:_SearchIter.replaced" ], "added_modules": null, "edited_entities": [ "babi/file.py:File.replace" ], "edited_modules": [ "babi/file.py:File", "babi/file.py:_SearchIter" ] }, "file": ...
asottile/babi
ea70fd2eab90a406f582e2bd886a30c9bad46c50
replace all does not account for line change The search and replace functionality does not account for line change when replacing all occurences. Example: Write a simple file with the following content: ``` A_A_ ``` and have the cursor on the last position. When replacing every `A` with `XXX` (or anything of l...
diff --git a/babi/file.py b/babi/file.py index 852c197..0165154 100644 --- a/babi/file.py +++ b/babi/file.py @@ -189,6 +189,11 @@ class _SearchIter: def __iter__(self) -> _SearchIter: return self + def replaced(self, y: int, match: Match[str], new: str) -> None: + if not self.wrapped or y != s...
asottile__covdefaults-57
[ { "changes": { "added_entities": [ "covdefaults.py:_lt", "covdefaults.py:_gt", "covdefaults.py:_version_pragmas" ], "added_modules": [ "covdefaults.py:_lt", "covdefaults.py:_gt", "covdefaults.py:_version_pragmas" ], "edited_entities":...
asottile/covdefaults
b33cb96b0b06669148e156af0a4c0c343a97b859
version specific coverage pragmas might be a fun little regex game, but it would be nice to support `# pragma: >=3.7 no cover` or some such
diff --git a/README.md b/README.md index 281cd5a..4b25ec2 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,13 @@ exclude_lines = if __name__ == ['"]__main__['"]:$ # additional platform related pragmas (see below) + # additional version related pragmas (see below) +partial_branches = + # a more stri...
asottile__covdefaults-97
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": null, "edited_modules": null }, "file": "covdefaults.py" } ]
asottile/covdefaults
9d6e5c5c20108daa74b72783ced5452fa84678da
Class-level `if TYPE_CHECKING` is reported as uncovered Example: ```python from typing import TYPE_CHECKING class Some: if TYPE_CHECKING: some_attr: str ``` Here `if TYPE_CHECKING:` is reported to be uncovered. <img width="679" alt="Снимок экрана 2022-12-03 в 14 21 00" src="https://user-images....
diff --git a/README.md b/README.md index 08a0078..2761af0 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ exclude_lines = ^\s*raise$ # typing-related code - ^if (False|TYPE_CHECKING): + ^\s*if (False|TYPE_CHECKING): : \.\.\.(\s*#.*)?$ ^ +\.\.\.$ -> ['"]?NoReturn['"]?: diff --gi...
asottile__dead-204
[ { "changes": { "added_entities": [ "dead.py:Visitor.root_scope_for_class_body" ], "added_modules": null, "edited_entities": [ "dead.py:Visitor.visit_ClassDef" ], "edited_modules": [ "dead.py:Visitor" ] }, "file": "dead.py" } ]
asottile/dead
d2d94828cfe205d294b5e551dfe187d77a1fe026
does not understand methods of returned classes a bit trickier since the scope target isn't quite right here? ```python def f(): class C: def handle(self): ... return C f().handle() ``` ```console $ dead handle is never read, defined in t.py:3 ```
diff --git a/dead.py b/dead.py index 5464817..17fb034 100644 --- a/dead.py +++ b/dead.py @@ -72,6 +72,17 @@ class Visitor(ast.NodeVisitor): finally: self.previous_scopes.append(self.scopes.pop()) + @contextlib.contextmanager + def root_scope_for_class_body(self) -> Generator[None]: + ...
asottile__dead-21
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "dead.py:Visitor.visit_Assign" ], "edited_modules": [ "dead.py:Visitor" ] }, "file": "dead.py" } ]
asottile/dead
85f5edbb84b5e118beab4be3346a630e41418a02
treat names in `__all__` as un-dead
diff --git a/dead.py b/dead.py index a8254d5..7879cc5 100644 --- a/dead.py +++ b/dead.py @@ -87,6 +87,17 @@ class Visitor(ast.NodeVisitor): for target in node.targets: if isinstance(target, ast.Name): self.defines[target.id].add(self.definition_str(node)) + + if...
asottile__dead-24
[ { "changes": { "added_entities": [ "dead.py:Visitor.scope", "dead.py:Visitor.define", "dead.py:Visitor.read", "dead.py:Visitor._is_stub_function" ], "added_modules": [ "dead.py:Scope" ], "edited_entities": [ "dead.py:Visitor.__init__"...
asottile/dead
f2c49508937f64f13cf650bfb11c29aba2d8aa36
Detect unused arguments A related feature that could be useful would be to detect "dead arguments," or function arguments not used by the function body. Here is an example of a dead argument found in pip: https://github.com/pypa/pip/pull/7015
diff --git a/dead.py b/dead.py index 7879cc5..019ee8e 100644 --- a/dead.py +++ b/dead.py @@ -8,6 +8,7 @@ import subprocess import tokenize from typing import DefaultDict from typing import Generator +from typing import List from typing import NewType from typing import Optional from typing import Pattern @@ -28,1...
asottile__dead-37
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "dead.py:Visitor.visit_FunctionDef" ], "edited_modules": [ "dead.py:Visitor" ] }, "file": "dead.py" } ]
asottile/dead
8817aa412121e319fc45dd5e269b0d009e7c2c06
Support posonlyargs they are notably missing in [this code](https://github.com/asottile/dead/blob/8817aa412121e319fc45dd5e269b0d009e7c2c06/dead.py#L133-L140)
diff --git a/dead.py b/dead.py index 5b3fdbc..a9f48c0 100644 --- a/dead.py +++ b/dead.py @@ -131,6 +131,7 @@ class Visitor(ast.NodeVisitor): with self.scope(): if not self._is_stub_function(node): for arg in ( + *getattr(node.args, 'posonlyargs', ()), ...
asottile__dead-49
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": null, "edited_modules": null }, "file": "dead.py" } ]
asottile/dead
d7152ac031b896f4655baef738eaffff04f8ada5
Crash caused by certain # type: ignore statements It appears that `dead` can't handle code that uses MyPy error codes in `type: ignore` directives. To reproduce: ```py def foo() -> int: return None # type: ignore[no-any-return] ``` Run `dead` with no arguments: ``` dargueta@tux ~/blah (master)$ dea...
diff --git a/dead.py b/dead.py index a2e28fa..2ab24d7 100644 --- a/dead.py +++ b/dead.py @@ -25,8 +25,14 @@ UsageMap = DefaultDict[str, Set[FileLine]] FunctionDef = Union[ast.AsyncFunctionDef, ast.FunctionDef] # https://github.com/python/typed_ast/blob/55420396/ast27/Parser/tokenizer.c#L102-L104 TYPE_COMMENT_RE = re...
asottile__flake8-typing-imports-12
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "flake8_typing_imports.py:Visitor.visit_ImportFrom" ], "edited_modules": [ "flake8_typing_imports.py:Visitor" ] }, "file": "flake8_typing_imports.py" } ]
asottile/flake8-typing-imports
90a95c5fd7c32eb586b1b14df36d37c66ecf1bb2
False positive with some.package.typing.SomeType Types imported from a package path that ends with `.typing` (not just the top-level `typing`) result in false positives. ``` $ find . ./x ./x/typing.py ./x/__init__.py $ cat x/typing.py ExampleType = str $ cat x/__init__.py from .typing import ExampleTy...
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d9f7ae5..6c8a1a3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v2.2.3 + rev: v2.4.0 hooks: - id: trailing-whitespace -...
asottile__git-code-debt-87
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": null, "edited_modules": null }, "file": "git_code_debt/metrics/common.py" }, { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "git_...
asottile/git-code-debt
6d3c4a0d3e5dd36482c010462e2b00e944e7a876
Use `identify` for code type identification Notably https://github.com/chriskuehl/identify/blob/39c020afff92d50d6ffb8b251f5bdc30d51ca96c/identify/identify.py#L69-L86
diff --git a/git_code_debt/metrics/common.py b/git_code_debt/metrics/common.py index 8cf025f..d91f272 100644 --- a/git_code_debt/metrics/common.py +++ b/git_code_debt/metrics/common.py @@ -1,56 +1,12 @@ from __future__ import absolute_import from __future__ import unicode_literals - -PYTHON = 'Python' -YAML = 'Yaml...
asottile__git-code-debt-91
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "git_code_debt/generate.py:get_metrics", "git_code_debt/generate.py:_get_metrics_inner", "git_code_debt/generate.py:load_data", "git_code_debt/generate.py:main" ], "ed...
asottile/git-code-debt
44b090434a24fe945747a98fddde5a051f0c7b1d
Add `exclude` pattern Add the ability to remove checked in files from the pattern which are not part of the codebase. For example: ```yaml exclude: '^vendor/' ```
diff --git a/git_code_debt/generate.py b/git_code_debt/generate.py index 90d72da..283b26c 100644 --- a/git_code_debt/generate.py +++ b/git_code_debt/generate.py @@ -29,7 +29,7 @@ from git_code_debt.write_logic import insert_metric_values from git_code_debt.write_logic import update_has_data -def get_metrics(commit...
asottile__pyupgrade-104
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": null, "edited_modules": null }, "file": "pyupgrade.py" } ]
asottile/pyupgrade
ce50197308d00f85aa728ad6afba33f3f1383544
raw-string rewrite with escaped newlines incorrect ```console $ cat t.py x = """\ foo\s """ print(x) $ python t.py foo\s $ pyupgrade t.py Rewriting t.py $ cat t.py x = r"""\ foo\s """ print(x) $ python t.py \ foo\s ```
diff --git a/pyupgrade.py b/pyupgrade.py index cdf8c14..f41fa13 100644 --- a/pyupgrade.py +++ b/pyupgrade.py @@ -429,7 +429,7 @@ ESCAPE_STARTS = frozenset(( 'N', 'u', 'U', )) ESCAPE_STARTS_BYTES = ESCAPE_STARTS - frozenset(('N', 'u', 'U')) -ESCAPE_RE = re.compile(r'\\.') +ESCAPE_RE = re.compile(r'\\.', re.DOTALL...
asottile__pyupgrade-112
[ { "changes": { "added_entities": [ "pyupgrade.py:_parse_string_literal", "pyupgrade.py:_fix_ur_literals" ], "added_modules": [ "pyupgrade.py:_parse_string_literal", "pyupgrade.py:_fix_ur_literals" ], "edited_entities": [ "pyupgrade.py:_fix_es...
asottile/pyupgrade
74925d02fe09e37a8aa7705cc1f3fd2a5248fe9b
Rewrite `ur` literals `ur` literals are invalid syntax in python3.x
diff --git a/README.md b/README.md index 42f687b..7d0d7c9 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,18 @@ u'\d' # u'\\d' # but in python3.x, that's our friend ☃ ``` +### `ur` string literals + +`ur'...'` literals are not valid in python 3.x + +```python +ur'foo' # u'foo' +ur'\s' # u'\\s...
asottile__pyupgrade-120
[ { "changes": { "added_entities": [ "pyupgrade.py:_is_string_prefix" ], "added_modules": [ "pyupgrade.py:_is_string_prefix" ], "edited_entities": [ "pyupgrade.py:_fix_tokens" ], "edited_modules": [ "pyupgrade.py:_fix_tokens" ] },...
asottile/pyupgrade
0df1eac05c9c37e2bfecf11895aee53a34c33afd
unicode literal fixer `return'foo'` Mistakenly does the following: ```diff - return'foo' + retrn'foo' ```
diff --git a/pyupgrade.py b/pyupgrade.py index a9c6cd5..0dcc2e0 100644 --- a/pyupgrade.py +++ b/pyupgrade.py @@ -490,6 +490,10 @@ def _fix_octal(s): return '0o' + s[1:] +def _is_string_prefix(token): + return token.name == 'NAME' and set(token.src.lower()) <= set('bfru') + + def _fix_tokens(contents_te...
asottile__pyupgrade-127
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "pyupgrade.py:_fix_extraneous_parens" ], "edited_modules": [ "pyupgrade.py:_fix_extraneous_parens" ] }, "file": "pyupgrade.py" } ]
asottile/pyupgrade
19d00664f519f628d41f39f7099a3fce1db46eca
Remove necessary extra parens from coroutine yield expression Currently this is happening, but it causes a `SyntaxError` -- the extra set of parens is necessary here: ```diff def run_tests(): url = options.url + '/getCaseCount' control_ws = yield websocket_connect(url, None) - num_tests = int((yiel...
diff --git a/pyupgrade.py b/pyupgrade.py index b67cbf7..b53cf3d 100644 --- a/pyupgrade.py +++ b/pyupgrade.py @@ -551,8 +551,8 @@ def _fix_extraneous_parens(tokens, i): depth = 1 while depth: i += 1 - # found comma at depth 1: this is a tuple - if depth == 1 and tokens[i].src == ',': + ...
asottile__pyupgrade-133
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "pyupgrade.py:_fix_py3_plus" ], "edited_modules": [ "pyupgrade.py:_fix_py3_plus" ] }, "file": "pyupgrade.py" } ]
asottile/pyupgrade
e19a16efb0f001f55fc96529199d498814016e30
Syntax errors created when removing with_metaclass Code such as ``` class EventProcessorMeta(six.with_metaclass(abc.ABCMeta)): ``` is being rewritten as invalid Python ``` class EventProcessorMeta(, metaclass=abc.ABCMeta): ```
diff --git a/pyupgrade.py b/pyupgrade.py index d3d7a55..6f2669b 100644 --- a/pyupgrade.py +++ b/pyupgrade.py @@ -914,7 +914,8 @@ SIX_CALLS = { 'assertRegex': '{args[0]}.assertRegex({rest})', } SIX_B_TMPL = 'b{args[0]}' -WITH_METACLASS_TMPL = '{rest}, metaclass={args[0]}' +WITH_METACLASS_NO_BASES_TMPL = 'metaclas...
asottile__pyupgrade-135
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "pyupgrade.py:FindSimpleFormats.visit_Call" ], "edited_modules": [ "pyupgrade.py:FindSimpleFormats" ] }, "file": "pyupgrade.py" } ]
asottile/pyupgrade
088722a3e5a9062f2173a5185bbb32eb466ac62e
Doesn't handle indexed format strings The following code which I tried to reduce (which I had no idea was possible): ```python thing = {'a': 1, 'b': 2} print('{0[a]} and {0[b]}'.format(thing)) ``` leads to ``` Traceback (most recent call last): File "/home/ethan/venv/bin/pyupgrade", line 10, in <module> ...
diff --git a/pyupgrade.py b/pyupgrade.py index 6f2669b..bf04191 100644 --- a/pyupgrade.py +++ b/pyupgrade.py @@ -1279,6 +1279,9 @@ class FindSimpleFormats(ast.NodeVisitor): # timid: could make the f-string longer if candidate and candidate in seen: brea...
asottile__pyupgrade-142
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "pyupgrade.py:_fix_escape_sequences" ], "edited_modules": [ "pyupgrade.py:_fix_escape_sequences" ] }, "file": "pyupgrade.py" } ]
asottile/pyupgrade
09ab4b1c47f4b1e10d3f12e65c46fb77b47a9fe2
py2-py3 invalid escape sequence: '\N' should get rewritten This is a syntax error in python3.x: ```python '\N' ```
diff --git a/README.md b/README.md index 8c379f5..4d842dd 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,9 @@ u'''foo''' # '''foo''' # `ur` is not a valid string prefix in python3 u'\d' # u'\\d' +# this fixes a syntax error in python3.3+ +'\N' # r'\N' + # note: pyupgrade is timid in one case (that's usu...
asottile__pyupgrade-143
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "pyupgrade.py:FindPy3Plus.__init__", "pyupgrade.py:FindPy3Plus.visit_Call", "pyupgrade.py:_fix_py3_plus" ], "edited_modules": [ "pyupgrade.py:FindPy3Plus", "py...
asottile/pyupgrade
d138fbaf32bb2f659a2d1c96417950a1efd58903
--py3-plus: `str('native literal')` -> 'native literal' In 2+3 code, a native literal (py2: bytes, py3: str) is often written as `str('foo')` -- this can be cleaned up automatically
diff --git a/pyupgrade.py b/pyupgrade.py index f1d25ec..2b251f4 100644 --- a/pyupgrade.py +++ b/pyupgrade.py @@ -904,7 +904,7 @@ SIX_TYPE_CTX_ATTRS = { } SIX_CALLS = { 'u': '{args[0]}', - 'byte2int': '{arg0}[0]', + 'byte2int': '{args[0]}[0]', 'indexbytes': '{args[0]}[{rest}]', 'iteritems': '{args...
asottile__pyupgrade-146
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "pyupgrade.py:_fix_format_literals", "pyupgrade.py:_fix_py2_compatible", "pyupgrade.py:_fix_percent_format", "pyupgrade.py:_fix_py3_plus", "pyupgrade.py:_fix_fstrings" ...
asottile/pyupgrade
b2e4ffe4faa3f3bba12f9e8b7a12d0847f716425
TokenError Thank you very much for writing this tool!! I want to run pyupgrade over a project that probably still contains code that raises a syntax error when imported in a python3 interpreter. ``pyupgrade --py36-plus`` outputs is the following in a python3.7 conda env: ``` filename1.py filename2.py Traceb...
diff --git a/pyupgrade.py b/pyupgrade.py index 2b251f4..31a603e 100644 --- a/pyupgrade.py +++ b/pyupgrade.py @@ -104,7 +104,10 @@ def _rewrite_string_literal(literal): def _fix_format_literals(contents_text): - tokens = src_to_tokens(contents_text) + try: + tokens = src_to_tokens(contents_text) + e...
asottile__pyupgrade-147
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "pyupgrade.py:FindPy3Plus.visit_ClassDef", "pyupgrade.py:FindPy3Plus.visit_Call" ], "edited_modules": [ "pyupgrade.py:FindPy3Plus" ] }, "file": "pyupgrade.py" ...
asottile/pyupgrade
a7601194da670e55b80dbb6903f7f6727e58f6fb
IndexError with pytest's fixtures.py ``` % pyupgrade --py3-only --keep-percent-format src/_pytest/fixtures.py Traceback (most recent call last): File "…/Vcs/pytest/.venv/bin/pyupgrade", line 11, in <module> sys.exit(main()) File "…/Vcs/pytest/.venv/lib/python3.7/site-packages/pyupgrade.py", line 1428, in m...
diff --git a/pyupgrade.py b/pyupgrade.py index 31a603e..b3c6f9c 100644 --- a/pyupgrade.py +++ b/pyupgrade.py @@ -1001,7 +1001,8 @@ class FindPy3Plus(ast.NodeVisitor): if ( len(node.bases) == 1 and isinstance(node.bases[0], ast.Call) and - self._is_six(node.bases...
asottile__pyupgrade-153
[ { "changes": { "added_entities": [ "pyupgrade.py:FindPy3Plus.visit_If", "pyupgrade.py:_fixup_dedent_tokens", "pyupgrade.py:_find_block_start", "pyupgrade.py:Block._initial_indent", "pyupgrade.py:Block._minimum_indent", "pyupgrade.py:Block.dedent", "p...
asottile/pyupgrade
8ba7b8b1844f76d2f3a8233cb1a632f3358fea9f
Rewrite `if PY2:` blocks in `--py3-plus` Ideally handle these different cases: ```python # input from six import PY2 if PY2: x = 5 else: x = 6 # output x = 6 ``` But also for ```python sys.version_info[0] == 2 sys.version_info < (3,) ``` etc. - [x] `six.PY2` - [x] `six.PY3` - [x] `not s...
diff --git a/pyupgrade.py b/pyupgrade.py index ac8bd70..b26904c 100644 --- a/pyupgrade.py +++ b/pyupgrade.py @@ -961,6 +961,10 @@ class FindPy3Plus(ast.NodeVisitor): self.bases_to_remove = set() self.encode_calls = {} + + self.if_py2_blocks = set() + self.if_py3_blocks = set() + ...
asottile__pyupgrade-158
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "pyupgrade.py:_remove_decorator" ], "edited_modules": [ "pyupgrade.py:_remove_decorator" ] }, "file": "pyupgrade.py" } ]
asottile/pyupgrade
19aac5a327570d4252c07cd8ce52c7ba504fe8d8
`add_metaclass` rewrite indentation is strange when indented Currently: ```diff if True: - @six.add_metaclass(M) - class C: pass + class C(metaclass=M): pass ```
diff --git a/pyupgrade.py b/pyupgrade.py index 8d11da1..ac8bd70 100644 --- a/pyupgrade.py +++ b/pyupgrade.py @@ -1114,6 +1114,8 @@ class FindPy3Plus(ast.NodeVisitor): def _remove_decorator(tokens, i): while tokens[i - 1].src != '@': i -= 1 + if i > 1 and tokens[i - 2].name not in {'NEWLINE', 'NL'}: + ...
asottile__pyupgrade-160
[ { "changes": { "added_entities": [ "pyupgrade.py:FindPy3Plus._is_version_info", "pyupgrade.py:FindPy3Plus._eq", "pyupgrade.py:FindPy3Plus._compare_to_3" ], "added_modules": null, "edited_entities": [ "pyupgrade.py:FindPy3Plus.__init__", "pyupgrade....
asottile/pyupgrade
2604d1a54f188938cb9e98b552eb60c9fbf84777
Rewrite `if PY2:` blocks in `--py3-plus` Ideally handle these different cases: ```python # input from six import PY2 if PY2: x = 5 else: x = 6 # output x = 6 ``` But also for ```python sys.version_info[0] == 2 sys.version_info < (3,) ``` etc. - [x] `six.PY2` - [x] `six.PY3` - [x] `not s...
diff --git a/README.md b/README.md index 0420938..11baadc 100644 --- a/README.md +++ b/README.md @@ -195,8 +195,8 @@ Availability: ```python def f(): - for x in y: # yield from y - yield x + for x in y: # yield from x + yield y for a, b in c: # yield from c yield (...
asottile__pyupgrade-165
[ { "changes": { "added_entities": [ "pyupgrade.py:_format_params" ], "added_modules": [ "pyupgrade.py:_format_params" ], "edited_entities": [ "pyupgrade.py:FindSimpleFormats.visit_Call", "pyupgrade.py:_to_fstring" ], "edited_modules": [ ...
asottile/pyupgrade
847d0caf9d57666ce06d58421cec982176e8a256
--py36-plus: KeyError on broken `.format()` call Currently garbage in garbage out, however this shouldn't crash: ```python '{}{}'.format(a) ``` ```console $ pyupgrade --py36-plus t.py Traceback (most recent call last): File "/home/asottile/workspace/ambassador/v/bin/pyupgrade", line 10, in <module> sy...
diff --git a/pyupgrade.py b/pyupgrade.py index b83d15e..6e6051f 100644 --- a/pyupgrade.py +++ b/pyupgrade.py @@ -1672,6 +1672,15 @@ def _starargs(call): ) +def _format_params(call): + params = {} + for i, arg in enumerate(call.args): + params[str(i)] = _unparse(arg) + for kwd in call.keywords: ...
asottile__pyupgrade-166
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "pyupgrade.py:_fix_py3_plus" ], "edited_modules": [ "pyupgrade.py:_fix_py3_plus" ] }, "file": "pyupgrade.py" } ]
asottile/pyupgrade
8cf438106eb8532a6e754017f8773dcfcef93556
function call rewrite broken when function is parenthesized A bit of an edge case, I haven't seen this break in the wild but it's certainly possible ```python ( six ).text_type(x) ``` This should produce ```python str(x) ``` But currently produces this broken syntax: ```python ( str(b) `...
diff --git a/pyupgrade.py b/pyupgrade.py index 6e6051f..7313835 100644 --- a/pyupgrade.py +++ b/pyupgrade.py @@ -1541,6 +1541,9 @@ def _fix_py3_plus(contents_text): else: j = i while tokens[j].src != node.attr: + # timid: if we see a parenthesis here, skip it + ...
asottile__pyupgrade-168
[ { "changes": { "added_entities": [ "pyupgrade.py:FindPy3Plus._visit_sync_func", "pyupgrade.py:FindPy3Plus.visit_AsyncFunctionDef" ], "added_modules": null, "edited_entities": [ "pyupgrade.py:FindPy3Plus.__init__", "pyupgrade.py:FindPy3Plus.visit_For", ...
asottile/pyupgrade
bddb4a06cf9373b77a49510ef0b8423468c03603
Should not rewrite to `yield from` inside `async def` oops, totally forgot about this. Currently this is happening but this is forbidden by [PEP 525](https://www.python.org/dev/peps/pep-0525/#asynchronous-yield-from) ```diff async def f(): - for x in y: - yield x + yield from y ```
diff --git a/pyupgrade.py b/pyupgrade.py index 7313835..cc8dc38 100644 --- a/pyupgrade.py +++ b/pyupgrade.py @@ -1023,6 +1023,7 @@ class FindPy3Plus(ast.NodeVisitor): self._class_info_stack = [] self._in_comp = 0 self.super_calls = {} + self._in_async_def = False self.yield_fr...
asottile__pyupgrade-190
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "pyupgrade.py:_victims" ], "edited_modules": [ "pyupgrade.py:_victims" ] }, "file": "pyupgrade.py" } ]
asottile/pyupgrade
8faebaaccd3bd25ed0643b2a07e8cd10b17a4f68
`set` with trailing comma after list causes syntax error ```python set( [ 1, 2, 3, ], ) ``` currently gets rewritten to (`SyntaxError`) ```python { 1, 2, 3, , } ```
diff --git a/pyupgrade.py b/pyupgrade.py index c7a8d26..2f8626c 100644 --- a/pyupgrade.py +++ b/pyupgrade.py @@ -233,6 +233,8 @@ def _victims(tokens, start, arg, gen): ends.extend((i - 1, i)) else: ends.append(i) + if len(brace_stack) > 1 and tokens[i + 1].src =...
asottile__pyupgrade-191
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "pyupgrade.py:FindPy3Plus.visit_Call", "pyupgrade.py:_fix_py3_plus" ], "edited_modules": [ "pyupgrade.py:FindPy3Plus", "pyupgrade.py:_fix_py3_plus" ] }, ...
asottile/pyupgrade
730dd770961576213ea06bcd8164b91196f1e903
`str()` native literal should be just `''` https://github.com/asottile/pyupgrade#forced-strnative-literals ```python str() # '' ```
diff --git a/README.md b/README.md index cada007..ec67866 100644 --- a/README.md +++ b/README.md @@ -181,6 +181,7 @@ Availability: - `--py3-plus` is passed on the commandline. ```python +str() # "''" str("foo") # "foo" ``` diff --git a/pyupgrade.py b/pyupgrade.py index a51cb50..9bbe886 100644 --- a/pyupg...
asottile__pyupgrade-192
[ { "changes": { "added_entities": [ "pyupgrade.py:FindPy3Plus._is_io_open" ], "added_modules": null, "edited_entities": [ "pyupgrade.py:FindPy3Plus.__init__", "pyupgrade.py:FindPy3Plus.visit_Call", "pyupgrade.py:_fix_py3_plus" ], "edited_modules...
asottile/pyupgrade
0c6149e665aeef2a5db423cfd145e6b7356fc160
--py3-plus: io.open => open
diff --git a/README.md b/README.md index 567b484..cfa3def 100644 --- a/README.md +++ b/README.md @@ -284,6 +284,20 @@ six.assertRaisesRegex(self, e, r, fn) # self.assertRaisesRegex(e, r, fn) six.assertRegex(self, s, r) # self.assertRegex(s, r) ``` +### `open` alias + +Availability: +- `--py3-plus` is ...
asottile__pyupgrade-195
[ { "changes": { "added_entities": [ "pyupgrade.py:FindSimpleFormats._parse_call" ], "added_modules": null, "edited_entities": [ "pyupgrade.py:FindSimpleFormats.visit_Call" ], "edited_modules": [ "pyupgrade.py:FindSimpleFormats" ] }, "file"...
asottile/pyupgrade
776d3fd38005862a891ce7a8e9c77fbfaadcca4c
--py36-plus: ValueError: Single '{' encountered in format string Invalid format failures are not skipped currently: ```python '{'.format(a) ``` ```console $ pyupgrade --py36-plus t.py Traceback (most recent call last): File "/home/asottile/workspace/ridemonitor/venv/bin/pyupgrade", line 10, in <module> ...
diff --git a/pyupgrade.py b/pyupgrade.py index 2347ec5..d24f9af 100644 --- a/pyupgrade.py +++ b/pyupgrade.py @@ -1982,18 +1982,12 @@ class FindSimpleFormats(ast.NodeVisitor): self.found = {} # type: Dict[Offset, ast.Call] def visit_Call(self, node): # type: (ast.Call) -> None - if ( - ...
asottile__pyupgrade-208
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "pyupgrade.py:FindPy3Plus.__init__", "pyupgrade.py:FindPy3Plus.visit_Call", "pyupgrade.py:_fix_py3_plus" ], "edited_modules": [ "pyupgrade.py:FindPy3Plus", "py...
asottile/pyupgrade
a5dc2d6c367df8bdac783c4d00cf6dc459f797cf
next(six.itervalues(d)) is rewritten to next(d.values()) ```console $ cat example.py import six print(next(six.itervalues({1: 2}))) $ python example.py 2 ``` ```console $ pyupgrade --py36-plus example.py Rewriting example.py ``` ```console $ cat example.py import six print(next({1: 2}.values())) ...
diff --git a/pyupgrade.py b/pyupgrade.py index d660a6d..fd897bc 100644 --- a/pyupgrade.py +++ b/pyupgrade.py @@ -1184,6 +1184,7 @@ class FindPy3Plus(ast.NodeVisitor): self.six_add_metaclass = set() # type: Set[ast.ClassDef] self.six_b = set() # type: Set[ast.Call] self.six_calls = {} # typ...
asottile__pyupgrade-217
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "pyupgrade.py:FindPy3Plus.visit_Call" ], "edited_modules": [ "pyupgrade.py:FindPy3Plus" ] }, "file": "pyupgrade.py" } ]
asottile/pyupgrade
0599e7b22e0757f8c655b8d93e3585a1a884b160
IndexError: list index out of range Tested with pyupgrade-1.25.0. Running the following command on the [more-itertools](https://github.com/erikrose/more-itertools) repository results in the following crash. Only occurs with the `--py3-plus` flag. ``` $ pyupgrade --py3-plus more_itertools/recipes.py Traceback (m...
diff --git a/pyupgrade.py b/pyupgrade.py index b451f58..161eeb9 100644 --- a/pyupgrade.py +++ b/pyupgrade.py @@ -1390,6 +1390,7 @@ class FindPy3Plus(ast.NodeVisitor): isinstance(node.func, ast.Name) and node.func.id == 'next' and not _starargs(node) and + ...
asottile__pyupgrade-238
[ { "changes": { "added_entities": [ "pyupgrade.py:_build_import_removals", "pyupgrade.py:_fix_import_removals" ], "added_modules": [ "pyupgrade.py:_build_import_removals", "pyupgrade.py:_fix_import_removals" ], "edited_entities": [ "pyupgrade....
asottile/pyupgrade
34a269fd7650d264e4de7603157c10d0a9bb8211
--py3-plus: remove all `from builtins import ...` imports See https://github.com/asottile/reorder_python_imports/issues/108
diff --git a/README.md b/README.md index 0af5a8b..9053360 100644 --- a/README.md +++ b/README.md @@ -220,6 +220,17 @@ Availability: -from __future__ import with_statement ``` +### Remove unnecessary py3-compat imports + +Availability: +- `--py3-plus` is passed on the commandline. + +```diff +-from io import open +-...
asottile__pyupgrade-242
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "pyupgrade.py:_fix_encode_to_binary" ], "edited_modules": [ "pyupgrade.py:_fix_encode_to_binary" ] }, "file": "pyupgrade.py" } ]
asottile/pyupgrade
34a269fd7650d264e4de7603157c10d0a9bb8211
Possible bug `"/\N{SNOWMAN}".encode("utf-8")` -> `br"/\N{SNOWMAN}"` Taken from running pyupgrade on Werkzeug's test suite. I think this is the wrong behavior as `"/\N{SNOWMAN}".encode("utf-8")` != `br"/\N{SNOWMAN}"` and therefore this tools should not convert the former to the latter.
diff --git a/pyupgrade.py b/pyupgrade.py index 25d7e99..1d0636f 100644 --- a/pyupgrade.py +++ b/pyupgrade.py @@ -656,6 +656,7 @@ def _fix_encode_to_binary(tokens, i): # type: (List[Token], int) -> None not _is_ascii(rest) or '\\u' in escapes or '\\U' in escapes or + ...
asottile__pyupgrade-243
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "pyupgrade.py:FindPy3Plus.visit_Call" ], "edited_modules": [ "pyupgrade.py:FindPy3Plus" ] }, "file": "pyupgrade.py" } ]
asottile/pyupgrade
438c83b7e11ff7f3894c25f6c2bee4cb3275a5c7
six: ensure_str / ensure_binary / ensure_text of a literal string while we generally can't fix the ensure_* variants, we can for string literals (as we're already doing for `str('...')` for example)
diff --git a/README.md b/README.md index eeb1a5f..7a7a469 100644 --- a/README.md +++ b/README.md @@ -331,6 +331,11 @@ six.get_function_globals(fn) # fn.__globals__ six.assertCountEqual(self, a1, a2) # self.assertCountEqual(a1, a2) six.assertRaisesRegex(self, e, r, fn) # self.assertRaisesRegex(e, r, ...
asottile__pyupgrade-247
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "pyupgrade.py:FindPy3Plus.__init__", "pyupgrade.py:FindPy3Plus.visit_Call", "pyupgrade.py:_fix_py3_plus" ], "edited_modules": [ "pyupgrade.py:FindPy3Plus", "py...
asottile/pyupgrade
711b1cdfa1b92eb035fe379b35d73a23859b5bc3
six.reraise: IndexError: list index out of range pyupgrade 1.26.0 Minimal test case. Requires using the `--py3-plus` argument. ``` def foo(func, arg): et, ev, _ = sys.exc_info() six.reraise(et, (ev[0], ev[1] + (" %s %s" % (func, arg)))) ``` ``` Traceback (most recent call last): File ".../venv/...
diff --git a/pyupgrade.py b/pyupgrade.py index 2f9170e..4a0f9c1 100644 --- a/pyupgrade.py +++ b/pyupgrade.py @@ -1137,10 +1137,9 @@ SIX_CALLS = { SIX_B_TMPL = 'b{args[0]}' WITH_METACLASS_NO_BASES_TMPL = 'metaclass={args[0]}' WITH_METACLASS_BASES_TMPL = '{rest}, metaclass={args[0]}' -SIX_RAISES = { - 'raise_from':...
asottile__pyupgrade-250
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "pyupgrade.py:FindPy3Plus.visit_Call", "pyupgrade.py:_fix_py3_plus" ], "edited_modules": [ "pyupgrade.py:FindPy3Plus", "pyupgrade.py:_fix_py3_plus" ] }, ...
asottile/pyupgrade
465effb0a65f3cd05d8b8201be4c8b899941b6e1
six.text_type('') takes two passes to resolve For example: ```console $ pip freeze | grep pyupgrade pyupgrade==1.26.1 $ cat 1.py six.text_type('') $ pyupgrade 1.py --py3-plus Rewriting 1.py $ cat 1.py str('') $ pyupgrade 1.py --py3-plus Rewriting 1.py $ cat 1.py '' $ pyupgrade 1.py --py3-plus $ ``` ...
diff --git a/pyupgrade.py b/pyupgrade.py index 4a0f9c1..6f99694 100644 --- a/pyupgrade.py +++ b/pyupgrade.py @@ -1140,6 +1140,7 @@ WITH_METACLASS_BASES_TMPL = '{rest}, metaclass={args[0]}' RAISE_FROM_TMPL = 'raise {args[0]} from {rest}' RERAISE_2_TMPL = 'raise {args[1]}.with_traceback(None)' RERAISE_3_TMPL = 'raise ...
asottile__pyupgrade-251
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "pyupgrade.py:_fix_py3_plus" ], "edited_modules": [ "pyupgrade.py:_fix_py3_plus" ] }, "file": "pyupgrade.py" } ]
asottile/pyupgrade
272ddebd33869c9d053710f40b19054a6e8d7684
metaclass extending object takes two passes to resolve minor thing, would be a useful improvement: ```python class C(six.with_metaclass(abc.ABCMeta, object)): pass ```
diff --git a/pyupgrade.py b/pyupgrade.py index 6f99694..1a80af6 100644 --- a/pyupgrade.py +++ b/pyupgrade.py @@ -2039,6 +2039,12 @@ def _fix_py3_plus(contents_text): # type: (str) -> str func_args, end = _parse_call_args(tokens, j) if len(func_args) == 1: tmpl = WITH_METACLAS...
asottile__pyupgrade-263
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "pyupgrade.py:FindPy3Plus.__init__", "pyupgrade.py:FindPy3Plus.visit_Call", "pyupgrade.py:_fix_py3_plus" ], "edited_modules": [ "pyupgrade.py:FindPy3Plus", "py...
asottile/pyupgrade
93a8c0f191e3ff269f5824bf1010f2920f0b1284
Replace open(file, "rU") with open(file)? "U" (universal newlines) `mode` was deprecated in Python 3.4 and the `newline=None` argument handles it instead. The default mode is `"r"` anyway
diff --git a/pyupgrade.py b/pyupgrade.py index 8e1fb1c..f675fc1 100644 --- a/pyupgrade.py +++ b/pyupgrade.py @@ -1225,6 +1225,7 @@ class FindPy3Plus(ast.NodeVisitor): set, ) # type: Dict[str, Set[str]] self.io_open_calls = set() # type: Set[Offset] + self.open_mode_calls = set() ...
asottile__pyupgrade-279
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "pyupgrade.py:_fix_percent_format", "pyupgrade.py:_fix_fstrings" ], "edited_modules": [ "pyupgrade.py:_fix_percent_format", "pyupgrade.py:_fix_fstrings" ] },...
asottile/pyupgrade
e41b9c75f0cb73ce01d90bbfcb6bea558c42ff5d
Valid f-string conversion throws KeyError While working on a conversion project, I noticed that certain files would throw `KeyError`'s for `\N{...}` strings. A minimal test case looks like: ```python world = "world" print("hello {} \N{snowman}".format(world)) ``` Which I would expect to be left alone or rewri...
diff --git a/pyupgrade.py b/pyupgrade.py index dab7eb2..bcd4250 100644 --- a/pyupgrade.py +++ b/pyupgrade.py @@ -1058,6 +1058,10 @@ def _fix_percent_format(contents_text: str) -> str: if node is None: continue + # TODO: handle \N escape sequences + if r'\N' in token.src: + ...
asottile__pyupgrade-283
[ { "changes": { "added_entities": [ "pyupgrade.py:FindPy36Plus.__init__", "pyupgrade.py:FindPy36Plus.visit_ImportFrom", "pyupgrade.py:FindPy36Plus._is_attr", "pyupgrade.py:FindPy36Plus.visit_Call", "pyupgrade.py:FindPy36Plus.visit_Assign", "pyupgrade.py:_repl...
asottile/pyupgrade
645dbea4874fa541dcdce1153fa1044e221b9bbb
rewrite typing.NamedTuple and typing.TypedDict to class form in --py36-plus ```python Employee = NamedTuple('Employee', [('name', str), ('id', int)]) ``` becomes ```python class Employee(NamedTuple): name: str id: int ```
diff --git a/README.md b/README.md index 8178ec6..4e3a01a 100644 --- a/README.md +++ b/README.md @@ -387,6 +387,34 @@ except OSError: raise ``` +### `typing.NamedTuple` / `typing.TypedDict` py36+ syntax + +Availability: +- `--py36-plus` is passed on the commandline. + +```python +# input +NT = typing.NamedTuple...
asottile__pyupgrade-286
[ { "changes": { "added_entities": [ "pyupgrade.py:FindPy3Plus._track_def_depth", "pyupgrade.py:FindPy3Plus._scope", "pyupgrade.py:FindPy3Plus.visit_Attribute", "pyupgrade.py:FindPy3Plus.visit_Name" ], "added_modules": null, "edited_entities": [ "pyu...
asottile/pyupgrade
71fcce45b826a5fe1695f4a8368197c3064cb303
'yield from' rewrite unsafe when looping variable is referenced later Consider the example code: ```py def foo(it): item = None for item in it: yield item print("Last item", item) ``` With `--py3-plus`, this is transformed to: ```py def foo(it): item = None yield from it ...
diff --git a/pyupgrade.py b/pyupgrade.py index 6173624..8e3bda3 100644 --- a/pyupgrade.py +++ b/pyupgrade.py @@ -2,6 +2,7 @@ import argparse import ast import codecs import collections +import contextlib import keyword import re import string @@ -1199,6 +1200,15 @@ class FindPy3Plus(ast.NodeVisitor): ...
asottile__pyupgrade-289
[ { "changes": { "added_entities": [ "pyupgrade.py:FindPy3Plus.visit_Assign" ], "added_modules": null, "edited_entities": [ "pyupgrade.py:FindPy3Plus.__init__", "pyupgrade.py:_fix_py3_plus" ], "edited_modules": [ "pyupgrade.py:FindPy3Plus", ...
asottile/pyupgrade
7c740d9f19c50f12c848fd081141dc750096ff30
Remove `__metaclass__ = type` at module scope in --py3-plus mode this was a way to trigger new-style classes in python2
diff --git a/README.md b/README.md index 1a2f764..f6f6ffc 100644 --- a/README.md +++ b/README.md @@ -170,11 +170,19 @@ class C(Base): Availability: - `--py3-plus` is passed on the commandline. +#### rewrites class declaration + ```python class C(object): pass # class C: pass class C(B, object): pass # class...
asottile__pyupgrade-295
[ { "changes": { "added_entities": [ "pyupgrade.py:FindPy3Plus._is_mock_mock", "pyupgrade.py:FindPy3Plus.visit_Import" ], "added_modules": null, "edited_entities": [ "pyupgrade.py:FindPy3Plus.__init__", "pyupgrade.py:FindPy3Plus.visit_ImportFrom", "p...
asottile/pyupgrade
6dfd917b3eaa409ce841b5a9faecc0f4396c0c14
Replace `from mock import` with `from unittest.mock import` https://docs.python.org/library/unittest.mock.html it was added in 3.3 as `unittest.mock` and backported to 2 as `mock`. Some codebases that used to be Python 2, still have `pip install mock` and `import mock` or `from mock import Mock` when they could forgo t...
diff --git a/README.md b/README.md index 2cd525c..dd2e81d 100644 --- a/README.md +++ b/README.md @@ -239,6 +239,16 @@ Availability: -from builtins import object # python-future ``` +### rewrite `mock` imports + +Availability: +- `--py3-plus` is passed on the commandline. + +```diff +-from mock import patch ++from ...
asottile__pyupgrade-296
[ { "changes": { "added_entities": [ "pyupgrade.py:FindPy3Plus._is_lru_cache" ], "added_modules": null, "edited_entities": [ "pyupgrade.py:FindPy3Plus.__init__", "pyupgrade.py:FindPy3Plus.visit_Call", "pyupgrade.py:_fix_py3_plus", "pyupgrade.py:_fix_...
asottile/pyupgrade
771453a0bcf4714802edf9c0494537a2a367f789
Remove parentheses from @functools.lru_cache() when upgrading to Python 3.8 https://docs.python.org/library/functools.html#functools.lru_cache In Python 3.7 you need to write `@lru_cache()`, in 3.8 you can just do `@lru_cache` without the parentheses. See https://bugs.python.org/issue36772 pyupgrade could remove ...
diff --git a/README.md b/README.md index 6b84e7a..2cd525c 100644 --- a/README.md +++ b/README.md @@ -438,3 +438,17 @@ Availability: _note_: `pyupgrade` is intentionally timid and will not create an f-string if it would make the expression longer or if the substitution parameters are anything but simple names or dott...
asottile__pyupgrade-308
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "pyupgrade.py:FindPy3Plus.visit_Name" ], "edited_modules": [ "pyupgrade.py:FindPy3Plus" ] }, "file": "pyupgrade.py" } ]
asottile/pyupgrade
6eed58483836b7c951f9d1173c1c39700b87c722
py3-plus: AssertionError: del statement in function pyupgrade 2.4.2 Minimal test case: ```py def foo(bar): del bar ``` ``` pyupgrade --py3-plus test.py ``` ``` Traceback (most recent call last): File "./venv/bin/pyupgrade", line 8, in <module> sys.exit(main()) File "/home/jon/venv/lib64...
diff --git a/pyupgrade.py b/pyupgrade.py index 8e3bda3..a49ef68 100644 --- a/pyupgrade.py +++ b/pyupgrade.py @@ -1448,7 +1448,7 @@ class FindPy3Plus(ast.NodeVisitor): if self._scope_stack: if isinstance(node.ctx, ast.Load): self._scope_stack[-1].reads.add(node.id) - eli...
asottile__pyupgrade-313
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "pyupgrade.py:FindPy3Plus.visit_Call" ], "edited_modules": [ "pyupgrade.py:FindPy3Plus" ] }, "file": "pyupgrade.py" } ]
asottile/pyupgrade
06444be5513ab77a149b7b4ae44d51803561e36f
open() rewrite doesn't always consider other positional args Minimal input: ```py with open('blah.txt', 'r', 'utf-8') as fp: pass ``` Actual output: ```py with open('blah.txt', 'utf-8') as fp: pass ``` Expected: ```py with open('blah.txt', encoding='utf-8') as fp: pass ``` The rew...
diff --git a/pyupgrade.py b/pyupgrade.py index a49ef68..45a13bb 100644 --- a/pyupgrade.py +++ b/pyupgrade.py @@ -1127,7 +1127,7 @@ SIX_NATIVE_STR = frozenset(('ensure_str', 'ensure_text', 'text_type')) U_MODE_REMOVE = frozenset(('U', 'Ur', 'rU', 'r', 'rt', 'tr')) U_MODE_REPLACE_R = frozenset(('Ub', 'bU')) U_MODE_REM...
asottile__pyupgrade-316
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "pyupgrade.py:FindPy3Plus.__init__", "pyupgrade.py:FindPy3Plus.visit_ImportFrom", "pyupgrade.py:FindPy3Plus.visit_Import", "pyupgrade.py:FindPy3Plus.visit_Attribute", "pyu...
asottile/pyupgrade
400b8bb96f70c7b21c2237dbfd89d4a3664bb875
some way to skip replacing mock with unittest.mock when you're using python 3.6 or 3.7 `unittest.mock.AsyncMock` is unavailable, but `mock.AsyncMock` is available if you're using the latest backport there should be some way to skip replacing `mock` with `unittest.mock`, or the fixer should be moved to `--py38-plus` ...
diff --git a/README.md b/README.md index ce8b62e..c16b744 100644 --- a/README.md +++ b/README.md @@ -243,6 +243,7 @@ Availability: Availability: - `--py3-plus` is passed on the commandline. +- [Unless `--keep-mock` is passed on the commandline](https://github.com/asottile/pyupgrade/issues/314). ```diff -from mo...
asottile__pyupgrade-317
[ { "changes": { "added_entities": [ "pyupgrade.py:_is_simple_base" ], "added_modules": [ "pyupgrade.py:_is_simple_base" ], "edited_entities": [ "pyupgrade.py:targets_same", "pyupgrade.py:FindPy3Plus.__init__", "pyupgrade.py:FindPy3Plus.visit_C...
asottile/pyupgrade
4656fbe8173b927bc215d09db1af0ef739741ad0
Rewrite old-style class `super()` calls as well For example: ```python class H(logging.StreamHandler): def __init__(self) -> None: logging.StreamHandler.__init__(self) # ... ``` should become ```python class H(logging.StreamHandler): def __init__(self) -> None: super().__...
diff --git a/pyupgrade.py b/pyupgrade.py index cb91999..71bb726 100644 --- a/pyupgrade.py +++ b/pyupgrade.py @@ -1157,8 +1157,8 @@ def fields_same(n1: ast.AST, n2: ast.AST) -> bool: return True -def targets_same(target: ast.AST, yield_value: ast.AST) -> bool: - for t1, t2 in zip(ast.walk(target), ast.walk(y...
asottile__pyupgrade-319
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "pyupgrade.py:Block.dedent" ], "edited_modules": [ "pyupgrade.py:Block" ] }, "file": "pyupgrade.py" } ]
asottile/pyupgrade
4656fbe8173b927bc215d09db1af0ef739741ad0
py2 / py3 branch rewrite breaks indentation ```python import six if six.PY2: # pragma: no cover (py2) def wsgi_to_text(s): # Use latin-1, the encoding of ip addresses isn't important (they'll # always be either ascii, or invalidated by the ipaddress module) return s.decode('LATIN-1'...
diff --git a/pyupgrade.py b/pyupgrade.py index cb91999..f6e8e94 100644 --- a/pyupgrade.py +++ b/pyupgrade.py @@ -1771,7 +1771,7 @@ class Block(NamedTuple): diff = self._minimum_indent(tokens) - self._initial_indent(tokens) for i in range(self.block, self.end): if ( - to...
asottile__pyupgrade-324
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "pyupgrade.py:FindPy36Plus.visit_Assign" ], "edited_modules": [ "pyupgrade.py:FindPy36Plus" ] }, "file": "pyupgrade.py" } ]
asottile/pyupgrade
efd108d02503dc0cba7661d9f5d80420d2ac246c
Rewriting TypedDict can lead to SyntaxError pyupgrade checks if the keys of a TypedDict are strings, but not if they are valid for usage in class syntax. Here's a minimal input: ```python from typing_extensions import TypedDict MyDict = TypedDict("MyDict", {"my-key": str, "another key": int}) ``` This i...
diff --git a/pyupgrade.py b/pyupgrade.py index f6e8e94..d740aa0 100644 --- a/pyupgrade.py +++ b/pyupgrade.py @@ -2449,6 +2449,7 @@ class FindPy36Plus(ast.NodeVisitor): isinstance(tup, ast.Tuple) and len(tup.elts) == 2 and isinstance(tup.elts[0],...
asottile__pyupgrade-330
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "pyupgrade.py:_fix_format_literal" ], "edited_modules": [ "pyupgrade.py:_fix_format_literal" ] }, "file": "pyupgrade.py" } ]
asottile/pyupgrade
162e74ef019982b8c744276103f1efdbac8459d0
pyupgrade on f-strings with .format() results in invalid f-string I understand that this is an edge-case because the input was buggy, but it _does_ convert running code into non-running code. ``` $ cat a.py print(f"foo {0}".format("bar")) $ python a.py foo 0 $ pyupgrade a.py Rewriting a.py $ cat a.py print(f...
diff --git a/pyupgrade.py b/pyupgrade.py index c463fcf..54bbe0d 100644 --- a/pyupgrade.py +++ b/pyupgrade.py @@ -587,6 +587,11 @@ def _fix_format_literal(tokens: List[Token], end: int) -> None: parsed_parts = [] last_int = -1 for i in parts: + # f'foo {0}'.format(...) would get turned into a Synta...
asottile__pyupgrade-332
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "pyupgrade.py:FindPy3Plus.visit_Call" ], "edited_modules": [ "pyupgrade.py:FindPy3Plus" ] }, "file": "pyupgrade.py" } ]
asottile/pyupgrade
13401ad8d06e9c9986909de5316135fe3dfc49ec
exception stack trace is replaced by a bare `raise` With python 3.7.4, the formatted exception stack trace will be replaced by a bare `raise`, and then make a syntax error. But the strange thing is that this occurs only when the statement is executed in the pre-commit hook of git, the replacement disappears if the s...
diff --git a/pyupgrade.py b/pyupgrade.py index 54bbe0d..8b47463 100644 --- a/pyupgrade.py +++ b/pyupgrade.py @@ -1558,7 +1558,7 @@ class FindPy3Plus(ast.NodeVisitor): elif ( isinstance(self._previous_node, ast.Expr) and self._is_six(node.func, ('reraise',)) and - ...
asottile__pyupgrade-347
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "pyupgrade.py:_fix_py3_plus" ], "edited_modules": [ "pyupgrade.py:_fix_py3_plus" ] }, "file": "pyupgrade.py" } ]
asottile/pyupgrade
1510dc5bf302e4218f6202185b6725e6a2653e07
pyupgrade incorrect output before ```python expectedResult = ( ":example.com \u0442\u0435\u0441\u0442 " "\u043d\u0438\u043a\r\n" ).encode("utf-8") ``` expected ```python b':example.com \xd1\x82\xd0\xb5\xd1\x81\xd1\x82 \xd0\xbd\xd0\xb8\xd0\xba\r\n' ``` or maybe this? ```python ':example.com тест ник\...
diff --git a/pyupgrade.py b/pyupgrade.py index 8fe8d11..79f2bb2 100644 --- a/pyupgrade.py +++ b/pyupgrade.py @@ -2233,7 +2233,7 @@ def _fix_py3_plus( victims = _victims(tokens, i, call, gen=False) del tokens[victims.starts[0] + 1:victims.ends[-1]] elif token.offset in visitor.encode_c...
asottile__pyupgrade-360
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "pyupgrade.py:FindPy3Plus.__init__", "pyupgrade.py:FindPy3Plus.visit_Call", "pyupgrade.py:_replace_call", "pyupgrade.py:_fix_py3_plus" ], "edited_modules": [ "...
asottile/pyupgrade
20d5c9ef3ca920c6332f2e0605fd0013225640f4
Six call removal breaks logic inside call before: ``` import six ...
diff --git a/pyupgrade.py b/pyupgrade.py index 79f2bb2..8c9f28c 100644 --- a/pyupgrade.py +++ b/pyupgrade.py @@ -57,6 +57,13 @@ _stdlib_parse_format = string.Formatter().parse _KEYWORDS = frozenset(keyword.kwlist) +_EXPR_NEEDS_PARENS: Tuple[Type[ast.expr], ...] = ( + ast.Await, ast.BinOp, ast.BoolOp, ast.Compar...
asottile__pyupgrade-380
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "pyupgrade.py:_build_import_removals" ], "edited_modules": [ "pyupgrade.py:_build_import_removals" ] }, "file": "pyupgrade.py" } ]
asottile/pyupgrade
d9e1f0886099fdb2d11e11f3d4fc1f4f11ef5fdf
Fails to run on python3.9 This is because there is no import removals defined for https://github.com/asottile/pyupgrade/blob/5e32666723/pyupgrade.py#L680-L693, and https://github.com/asottile/pyupgrade/blob/5e32666723/pyupgrade.py#L732 lookup fails. Perhaps instead of ``[]`` it should use ``.get``? ``` venv/bin/pyu...
diff --git a/pyupgrade.py b/pyupgrade.py index 796064f..254c9ff 100644 --- a/pyupgrade.py +++ b/pyupgrade.py @@ -690,6 +690,7 @@ def _build_import_removals() -> Dict[MinVersion, Dict[str, Tuple[str, ...]]]: ((3, 6), ()), ((3, 7), ('generator_stop',)), ((3, 8), ()), + ((3, 9), ()), ...
asottile__pyupgrade-409
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": null, "edited_modules": [ "pyupgrade/_data.py:Settings" ] }, "file": "pyupgrade/_data.py" }, { "changes": { "added_entities": null, "added_modules": null, "edi...
asottile/pyupgrade
7849a12f40d0fad949159b1e76e324cc305f80dc
IndentationError: unindent does not match any outer indentation level To reproduce: ```python # t.py from __future__ import annotations from typing import ( Sequence, Union, ) def sort_index( self, ascending: Union[Union[bool, int], Sequence[Union[bool, int]]], ): indexer = get_i...
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f92aa79..13c1a41 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,20 +11,20 @@ repos: - id: requirements-txt-fixer - id: trailing-whitespace - repo: https://github.com/asottile/setup-cfg-fmt - rev: v1.17.0 ...
asottile__pyupgrade-418
[ { "changes": { "added_entities": [ "pyupgrade/_main.py:_typed_class_replacement" ], "added_modules": [ "pyupgrade/_main.py:_typed_class_replacement" ], "edited_entities": [ "pyupgrade/_main.py:FindPy36Plus.visit_Assign", "pyupgrade/_main.py:_replace_...
asottile/pyupgrade
1923d1ca70e165f98ad5fe1923d9a67f20bdc8a6
Support translating TypedDict's with 'total' option Currently pyupgrade skips converting a TypedDict to python 3.6 format if there is a `total` option. https://www.python.org/dev/peps/pep-0589/#totality
diff --git a/pyupgrade/_main.py b/pyupgrade/_main.py index 86c3a97..e303500 100644 --- a/pyupgrade/_main.py +++ b/pyupgrade/_main.py @@ -644,7 +644,11 @@ class FindPy36Plus(ast.NodeVisitor): 'TypedDict', ) and len(node.value.args) == 1 and - ...
asottile__pyupgrade-53
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "pyupgrade.py:_to_fstring" ], "edited_modules": [ "pyupgrade.py:_to_fstring" ] }, "file": "pyupgrade.py" } ]
asottile/pyupgrade
a37342a71a84f3046b90d46b656b4cae16266617
KeyError running with --py36-plus on matplotlib's ticker.py Running pyupgrade 1.5 on matplotlib's ticker.py as of, say, mpl3.0rc2 (https://github.com/matplotlib/matplotlib/blob/v3.0.0rc2/lib/matplotlib/ticker.py) gives me ``` Traceback (most recent call last): File "/usr/bin/pyupgrade", line 11, in <module> s...
diff --git a/pyupgrade.py b/pyupgrade.py index 486a440..b9cb902 100644 --- a/pyupgrade.py +++ b/pyupgrade.py @@ -818,10 +818,12 @@ def _to_fstring(src, call): params[kwd.arg] = _unparse(kwd.value) parts = [] - for i, (s, name, spec, conv) in enumerate(parse_format('f' + src)): + i = 0 + for s, ...
asottile__pyupgrade-530
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "pyupgrade/_plugins/versioned_branches.py:_compare_to_3", "pyupgrade/_plugins/versioned_branches.py:visit_If" ], "edited_modules": [ "pyupgrade/_plugins/versioned_branches.py:...
asottile/pyupgrade
f86dc652e1b77ad9d6632f16caebabbaa452a634
Feature idea/question: cleanup conditionals on sys.version_info This is more of a question at this point: I wonder if it _would_ be possible to do this with pyupgrade. If it is, I'll attempt to write a patch, otherwise you can just close this ! ## input assuming we run pyupgrade with the `--py39` flag ```python...
diff --git a/README.md b/README.md index 1366c75..45f5486 100644 --- a/README.md +++ b/README.md @@ -294,21 +294,58 @@ def f(): yield (a, b) ``` -### `if PY2` blocks +### Python2 and old Python3.x blocks Availability: - `--py3-plus` is passed on the commandline. ```python # input -if six.PY2: #...
asottile__pyupgrade-542
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "pyupgrade/_main.py:parse_format", "pyupgrade/_main.py:unparse_parsed_string", "pyupgrade/_main.py:_fix_py36_plus" ], "edited_modules": [ "pyupgrade/_main.py:parse_for...
asottile/pyupgrade
748a1f09de1123e65c29b32082dbfe370fc4cb28
Perform rewrite of format literals containing \N escapes #279 prevents the crash / incorrect behaviour from #278, but this should be supported -- shouldn't be too difficult but will likely need to reimplement the format string parsing (the stdlib one doesn't notice these escape sequences, probably because they're gone ...
diff --git a/pyupgrade/_main.py b/pyupgrade/_main.py index 291fc47..2675619 100644 --- a/pyupgrade/_main.py +++ b/pyupgrade/_main.py @@ -31,8 +31,10 @@ from pyupgrade._data import FUNCS from pyupgrade._data import Settings from pyupgrade._data import Version from pyupgrade._data import visit +from pyupgrade._string_...
asottile__pyupgrade-545
[ { "changes": { "added_entities": [ "pyupgrade/_plugins/legacy.py:_is_staticmethod_decorated" ], "added_modules": [ "pyupgrade/_plugins/legacy.py:_is_staticmethod_decorated" ], "edited_entities": [ "pyupgrade/_plugins/legacy.py:Visitor.visit_Call" ], ...
asottile/pyupgrade
a2f517f0103c1f74bffbc06be510bcec4cd181ec
Rewriting old-style superclasses removes args for static methods ```python class Parent: @staticmethod def func(arg): return 0 class Child(Parent): @staticmethod def func(arg): return Parent.func(arg) ``` rewrites `Parent._thing(arg)` to `super()._thing()` rather than `supe...
diff --git a/pyupgrade/_plugins/legacy.py b/pyupgrade/_plugins/legacy.py index f7ba376..3ae702a 100644 --- a/pyupgrade/_plugins/legacy.py +++ b/pyupgrade/_plugins/legacy.py @@ -8,6 +8,7 @@ from typing import Iterable from typing import List from typing import Set from typing import Tuple +from typing import Union ...
asottile__pyupgrade-568
[ { "changes": { "added_entities": [ "pyupgrade/_plugins/typing_pep604.py:_any_arg_is_str" ], "added_modules": [ "pyupgrade/_plugins/typing_pep604.py:_any_arg_is_str" ], "edited_entities": [ "pyupgrade/_plugins/typing_pep604.py:visit_Subscript" ], ...
asottile/pyupgrade
f5b16fcfdffb755b8ca41b9d1bc343075853a5ab
Do not upgrade string annotations types wrapped in `Optional` to new Union | formatting Simplistic python code: ```python qqq: "int" | None = 0 ``` Output: ``` python qqq.py Traceback (most recent call last): File "qqq.py", line 2, in <module> qqq: "int" | None = 0 TypeError: unsupported operand t...
diff --git a/pyupgrade/_plugins/typing_pep604.py b/pyupgrade/_plugins/typing_pep604.py index 6ffcc20..8d55009 100644 --- a/pyupgrade/_plugins/typing_pep604.py +++ b/pyupgrade/_plugins/typing_pep604.py @@ -126,6 +126,15 @@ def _supported_version(state: State) -> bool: ) +def _any_arg_is_str(node_slice: ast.expr...
asottile__pyupgrade-584
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "pyupgrade/_plugins/six_calls.py:visit_Call" ], "edited_modules": [ "pyupgrade/_plugins/six_calls.py:visit_Call" ] }, "file": "pyupgrade/_plugins/six_calls.py" } ]
asottile/pyupgrade
234e07160f1d6a171b1100de7046a92d4866e0ba
Incorrect rewrite of six.reraise with traceback as keyword argument Reduced from real code in Launchpad: ``` $ cat t.py import sys from six import reraise exc_info = sys.exc_info() reraise(exc_info[0], exc_info[1], tb=exc_info[2]) $ pyupgrade --py3-plus t.py Rewriting t.py $ cat t.py import sys from ...
diff --git a/pyupgrade/_plugins/six_calls.py b/pyupgrade/_plugins/six_calls.py index 90c4ee3..ac58fd5 100644 --- a/pyupgrade/_plugins/six_calls.py +++ b/pyupgrade/_plugins/six_calls.py @@ -172,13 +172,21 @@ def visit_Call( ('reraise',), ) ): - if len(node.args) == 2 and not has...
asottile__pyupgrade-611
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "pyupgrade/_plugins/subprocess_run.py:visit_Call" ], "edited_modules": [ "pyupgrade/_plugins/subprocess_run.py:visit_Call" ] }, "file": "pyupgrade/_plugins/subprocess_ru...
asottile/pyupgrade
d71f806ce2fa0799c8dbe8cdcba7f9d5af2fd167
universal_newlines conversion can lead to doubled "text" If for some reason `universal_newlines` and `text` are both passed to a `subprocess.run()`, replacing the first with the latter causes `text` to be doubled. I suggest to in such case remove `universal_newlines`, if `text` has priority anyway with Python 3.6 and l...
diff --git a/pyupgrade/_plugins/subprocess_run.py b/pyupgrade/_plugins/subprocess_run.py index 48affbe..53cc03d 100644 --- a/pyupgrade/_plugins/subprocess_run.py +++ b/pyupgrade/_plugins/subprocess_run.py @@ -79,6 +79,7 @@ def visit_Call( stdout_idx = None stderr_idx = None universal_newlines...
asottile__pyupgrade-650
[ { "changes": { "added_entities": [ "pyupgrade/_plugins/native_literals.py:_fix_literal" ], "added_modules": [ "pyupgrade/_plugins/native_literals.py:_fix_literal" ], "edited_entities": [ "pyupgrade/_plugins/native_literals.py:_fix_native_str", "pyupg...
asottile/pyupgrade
54356ffa8d065d6ea9361f0944d3189101ae359e
rewrite bytes(b'foo') -> b'foo' looks like this was a somewhat common mistake when doing a python2/python3 port similar to the `str('string literal')` fix that's already happening in pyupgrade
diff --git a/pyupgrade/_plugins/native_literals.py b/pyupgrade/_plugins/native_literals.py index fce35cb..e95dfe7 100644 --- a/pyupgrade/_plugins/native_literals.py +++ b/pyupgrade/_plugins/native_literals.py @@ -1,6 +1,7 @@ from __future__ import annotations import ast +import functools from typing import Iterabl...
asottile__pyupgrade-656
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "pyupgrade/_plugins/open_mode.py:visit_Call" ], "edited_modules": [ "pyupgrade/_plugins/open_mode.py:visit_Call" ] }, "file": "pyupgrade/_plugins/open_mode.py" } ]
asottile/pyupgrade
85f02f45f0d2889f3826f16b60f27188ea84c1ae
two steps to converge: io.open(..., 'r') the first step goes to `open(..., 'r')` and the second step goes to `open(...)`
diff --git a/pyupgrade/_plugins/open_mode.py b/pyupgrade/_plugins/open_mode.py index fb3f3b6..bc3169a 100644 --- a/pyupgrade/_plugins/open_mode.py +++ b/pyupgrade/_plugins/open_mode.py @@ -55,8 +55,17 @@ def visit_Call( ) -> Iterable[tuple[Offset, TokenFunc]]: if ( state.settings.min_version >= (3,) ...
asottile__pyupgrade-67
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "pyupgrade.py:fix_file", "pyupgrade.py:main" ], "edited_modules": [ "pyupgrade.py:fix_file", "pyupgrade.py:main" ] }, "file": "pyupgrade.py" } ]
asottile/pyupgrade
b4fbe44b884dd2264eeb73030941f040441ea9ed
Add the ability to disable specific upgrades E.g. our style guide forces printf-like syntax (we switch to C-like languages often and cut the corners) and we have to revert the corresponding upgrades as in https://github.com/src-d/ml/pull/322#pullrequestreview-162382042 So would be nice to enable/disable features bes...
diff --git a/README.md b/README.md index 7612556..7285a1c 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,9 @@ dict([(a, b) for a, b in y) # {a: b for a, b in y} ### printf-style string formatting +Availability: +- Unless `--keep-percent-format` is passed. + ```python '%s %s' % (a, b) # '{}...
asottile__pyupgrade-707
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "pyupgrade/_plugins/legacy.py:Visitor.visit_Call" ], "edited_modules": [ "pyupgrade/_plugins/legacy.py:Visitor" ] }, "file": "pyupgrade/_plugins/legacy.py" } ]
asottile/pyupgrade
d9461f58d40a68b07879bf36190185d57b078c7d
super() calls in nested classes aren't updated It appears that calls to `super()` within inner/nested classes aren't updated as I would expect. Minimal reproduction: `.pre-commit-config.yaml`: ```yaml repos: - repo: https://github.com/asottile/pyupgrade rev: v2.37.3 hooks: - id: pyupgrade ...
diff --git a/pyupgrade/_plugins/legacy.py b/pyupgrade/_plugins/legacy.py index 4c7897e..568eebe 100644 --- a/pyupgrade/_plugins/legacy.py +++ b/pyupgrade/_plugins/legacy.py @@ -131,19 +131,42 @@ class Visitor(ast.NodeVisitor): isinstance(node.func, ast.Name) and node.func.id == 'super'...
asottile__pyupgrade-767
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "pyupgrade/_plugins/typing_classes.py:_unparse" ], "edited_modules": [ "pyupgrade/_plugins/typing_classes.py:_unparse" ] }, "file": "pyupgrade/_plugins/typing_classes.py...
asottile/pyupgrade
a19e73372afc7ad8462488148c8ebeb9d82a864a
NotImplementedError on optional TypedDict union in functional definition ```python Traceback (most recent call last): File "/Users/v832272/.asdf/installs/python/3.11.0/bin/pyupgrade", line 8, in <module> sys.exit(main()) ^^^^^^ File "/Users/v832272/.asdf/installs/python/3.11.0/lib/python3.11/s...
diff --git a/pyupgrade/_plugins/typing_classes.py b/pyupgrade/_plugins/typing_classes.py index d0afe13..387f18c 100644 --- a/pyupgrade/_plugins/typing_classes.py +++ b/pyupgrade/_plugins/typing_classes.py @@ -46,6 +46,8 @@ def _unparse(node: ast.expr) -> str: return '[{}]'.format(', '.join(_unparse(elt) for el...
asottile__pyupgrade-77
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": null, "edited_modules": null }, "file": "pyupgrade.py" } ]
asottile/pyupgrade
8fd39bbab6e34046300b4f6d7300153e511137ce
pyupgrade is introducing a raw string where a line continuation is being used. Hi. The pyupgrade tool is introducing a raw string where a line continuation is being used. Check this example below: ```python import textwrap def test_importerror(tmpdir): print(tmpdir) p1 = tmpdir.join("test1.txt") ...
diff --git a/pyupgrade.py b/pyupgrade.py index d6a196c..928b97e 100644 --- a/pyupgrade.py +++ b/pyupgrade.py @@ -437,7 +437,7 @@ def _fix_unicode_literals(contents_text, py3_plus): # https://docs.python.org/3/reference/lexical_analysis.html ESCAPE_STARTS = frozenset(( - '\n', '\\', "'", '"', 'a', 'b', 'f', 'n', ...
asottile__pyupgrade-818
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "pyupgrade/_plugins/imports.py:FromImport.parse", "pyupgrade/_plugins/imports.py:FromImport.remove_parts" ], "edited_modules": [ "pyupgrade/_plugins/imports.py:FromImport" ...
asottile/pyupgrade
f8932f0b87fa3688b219f7389bcf91537ae8a4d6
Broken imports When rewriting the following code ```python from typing import Optional, Sequence as SequenceType ``` pyupgrade duplicates the `as SequenceType`: ```python from typing import Optional as SequenceType from collections.abc import Sequence as SequenceType ``` I've ran it with `pyupgrade --p...
diff --git a/pyupgrade/_plugins/imports.py b/pyupgrade/_plugins/imports.py index f6e0359..823d634 100644 --- a/pyupgrade/_plugins/imports.py +++ b/pyupgrade/_plugins/imports.py @@ -281,6 +281,7 @@ class FromImport(NamedTuple): mod_start: int mod_end: int names: tuple[int, ...] + ends: tuple[int, ...] ...
asottile__pyupgrade-84
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "pyupgrade.py:_percent_to_format" ], "edited_modules": [ "pyupgrade.py:_percent_to_format" ] }, "file": "pyupgrade.py" } ]
asottile/pyupgrade
bbe34c45db1fa1c54969f590fc35571a636132b4
Behaviour change after upgrading '%9s' to '{:9}' This pyupgrade change (https://github.com/hugovk/yamllint/commit/25e8e9be0838bff930b3b204360fc24385b6edbf) fails indentation-related unit tests which previously passed: ```diff - output += '%9s %s\n' % (token_type, + output += '{:9} {}\n'.forma...
diff --git a/pyupgrade.py b/pyupgrade.py index 66e1094..18345dc 100644 --- a/pyupgrade.py +++ b/pyupgrade.py @@ -609,6 +609,8 @@ def _percent_to_format(s): if conversion == '%': return s + '%' parts = [s, '{'] + if width and conversion == 's' and not conversion_flag...
asottile__pyupgrade-858
[ { "changes": { "added_entities": [ "pyupgrade/_plugins/versioned_branches.py:_fix_py2_convert_elif", "pyupgrade/_plugins/versioned_branches.py:_fix_py3_convert_elif" ], "added_modules": [ "pyupgrade/_plugins/versioned_branches.py:_fix_py2_convert_elif", "pyupgra...
asottile/pyupgrade
a62c9667843ed65eaf617eb2dc0051d1966d74d1
if (version check) + elif (version check) is not rewritten! in `--py38-plus` mode I expect: ```diff - if sys.version_info < (3, 8): # pragma: <3.8 cover - msg = "SyntaxError: can't assign to function call (<unknown>, line 1)" - elif sys.version_info < (3, 10): # pragma: no cover + if sys.versio...
diff --git a/pyupgrade/_plugins/versioned_branches.py b/pyupgrade/_plugins/versioned_branches.py index ee0c450..05c776a 100644 --- a/pyupgrade/_plugins/versioned_branches.py +++ b/pyupgrade/_plugins/versioned_branches.py @@ -45,6 +45,20 @@ def _fix_py2_block(i: int, tokens: list[Token]) -> None: del tokens[if_...
asottile__pyupgrade-890
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "pyupgrade/_string_helpers.py:parse_format" ], "edited_modules": [ "pyupgrade/_string_helpers.py:parse_format" ] }, "file": "pyupgrade/_string_helpers.py" } ]
asottile/pyupgrade
a61ea875545997641089caf87b9f1cf623d059fe
Error after upgrading a formatted sting starting with a variable If I run pyupgrade on this string : **'{}\N{NO-BREAK SPACE}'.format(currency.symbol or "")** I get this line as an output : "\N{NO-BREAK SPACE}".format(currency.symbol or "") Wich causes an error
diff --git a/pyupgrade/_string_helpers.py b/pyupgrade/_string_helpers.py index 4271839..1c15655 100644 --- a/pyupgrade/_string_helpers.py +++ b/pyupgrade/_string_helpers.py @@ -19,7 +19,7 @@ def parse_format(s: str) -> list[DotFormatPart]: for part in NAMED_UNICODE_RE.split(s): if NAMED_UNICODE_RE.fullm...
asottile__pyupgrade-9
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "pyupgrade.py:_fix_format_literals", "pyupgrade.py:_get_victims" ], "edited_modules": [ "pyupgrade.py:_fix_format_literals", "pyupgrade.py:_get_victims" ] },...
asottile/pyupgrade
47f2b57f4b8ea963617199885ff46e0af7e63e45
SyntaxError rewriting dict(thing,) or set(thing,) (trailing comma) For example ```python >>> set(x for x in range(1),) {0} >>> {x for x in range(1),} File "<stdin>", line 1 {x for x in range(1),} ^ SyntaxError: invalid syntax ```
diff --git a/pyupgrade.py b/pyupgrade.py index d2a6990..eafc8a3 100644 --- a/pyupgrade.py +++ b/pyupgrade.py @@ -46,6 +46,7 @@ def unparse_parsed_string(parsed): UNIMPORTANT_WS = 'UNIMPORTANT_WS' +NON_CODING_TOKENS = frozenset(('COMMENT', 'NL', UNIMPORTANT_WS)) Token = collections.namedtuple( 'Token', ('name...
asottile__pyupgrade-933
[ { "changes": { "added_entities": [ "pyupgrade/_token_helpers.py:_arg_str_no_comment" ], "added_modules": [ "pyupgrade/_token_helpers.py:_arg_str_no_comment" ], "edited_entities": [ "pyupgrade/_token_helpers.py:constant_fold_tuple" ], "edited_modu...
asottile/pyupgrade
85c6837431a2eebdc9809f80b7adc529525ea73c
multi-line exception with duplicate BaseException and comments gives invalid code ## before ```python try: ... except ( BaseException, BaseException # b ): ... ``` ## after ```python try: ... except (BaseException, BaseException # b): ... ``` ## info * ...
diff --git a/pyupgrade/_token_helpers.py b/pyupgrade/_token_helpers.py index 5936ab7..e932c04 100644 --- a/pyupgrade/_token_helpers.py +++ b/pyupgrade/_token_helpers.py @@ -369,6 +369,14 @@ def arg_str(tokens: list[Token], start: int, end: int) -> str: return tokens_to_src(tokens[start:end]).strip() +def _arg_...
asottile__pyupgrade-939
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "pyupgrade/_plugins/shlex_join.py:visit_Call" ], "edited_modules": [ "pyupgrade/_plugins/shlex_join.py:visit_Call" ] }, "file": "pyupgrade/_plugins/shlex_join.py" } ]
asottile/pyupgrade
3e4103f24bfd10701d1913f7cc969b44fe165525
"".join(shlex.quote(...) ...) to shlex.join(...) is too eager Consider the following: ``` import shlex trash_bin = "garbage".join(shlex.quote(a) for a in ["some", "quotable strings"]) ``` If I run `pyupgrade --py310-plus` on this, I get `trash_bin = shlex.join(["some", "quotable strings"])`. But this is not ...
diff --git a/pyupgrade/_plugins/shlex_join.py b/pyupgrade/_plugins/shlex_join.py index 1406756..1718ff9 100644 --- a/pyupgrade/_plugins/shlex_join.py +++ b/pyupgrade/_plugins/shlex_join.py @@ -39,7 +39,7 @@ def visit_Call( if ( isinstance(node.func, ast.Attribute) and isinstance(node.func...
asottile__setup-cfg-fmt-107
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "setup_cfg_fmt.py:_req_base" ], "edited_modules": [ "setup_cfg_fmt.py:_req_base" ] }, "file": "setup_cfg_fmt.py" } ]
asottile/setup-cfg-fmt
1663a68ea45ed764f22ff1415edaea28ccbe118d
normalize requirements names to be dashed-names
diff --git a/setup_cfg_fmt.py b/setup_cfg_fmt.py index be8eb0d..a2b637e 100644 --- a/setup_cfg_fmt.py +++ b/setup_cfg_fmt.py @@ -259,7 +259,8 @@ def _normalize_lib(lib: str) -> str: def _req_base(lib: str) -> str: basem = re.match(BASE_NAME_REGEX, lib) assert basem - return basem.group(0) + # pip repla...
asottile__setup-cfg-fmt-132
[ { "changes": { "added_entities": [ "setup_cfg_fmt.py:NoTransformConfigParser.optionxform" ], "added_modules": [ "setup_cfg_fmt.py:NoTransformConfigParser" ], "edited_entities": [ "setup_cfg_fmt.py:_tox_envlist", "setup_cfg_fmt.py:_python_requires", ...
asottile/setup-cfg-fmt
5efd7109ad526cf4b5b5de7dff003eb5aa1e4058
configparser is downcasing keys in unrelated sections for instance this doesn't roundtrip: ```ini [tool:pytest] DJANGO_SETTINGS_MODULE = test.test ```
diff --git a/setup_cfg_fmt.py b/setup_cfg_fmt.py index 34e3824..afd3a45 100644 --- a/setup_cfg_fmt.py +++ b/setup_cfg_fmt.py @@ -75,6 +75,12 @@ TOX_TO_CLASSIFIERS = { } +class NoTransformConfigParser(configparser.RawConfigParser): + def optionxform(self, s: str) -> str: + """disable default lower-casing"...
asottile__setup-cfg-fmt-150
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": [ "setup_cfg_fmt.py:_first_file" ], "edited_modules": [ "setup_cfg_fmt.py:_first_file" ] }, "file": "setup_cfg_fmt.py" } ]
asottile/setup-cfg-fmt
97c79d263a803b0dd7a5cea649b3ac1ae4b9e2de
fix: add option for defining long_description Hello! Thanks for this awesome project and you determination to open source. I use Asciidoctor for documentation. Because PyPI does not support rendering this format, I made a CI workflow to convert my README.adoc to a README.md before building the python wheels and ...
diff --git a/README.md b/README.md index f6c2f8c..cd5ecc3 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,7 @@ setuptools allows dashed names but does not document them. +long_description = file: README.md ``` -### adds `long_description` if `README.md` is present +### adds `long_description` if `README` is pre...
asottile__setup-cfg-fmt-41
[ { "changes": { "added_entities": null, "added_modules": null, "edited_entities": null, "edited_modules": null }, "file": "setup_cfg_fmt.py" } ]
asottile/setup-cfg-fmt
d6dc55e3b6e5b77c93f9641b6c7cbead7e6cfa8f
author and maintainer should be kept beside each other found via https://github.com/pfmoore/editables/pull/2
diff --git a/setup_cfg_fmt.py b/setup_cfg_fmt.py index f7c674e..1dee7b6 100644 --- a/setup_cfg_fmt.py +++ b/setup_cfg_fmt.py @@ -20,8 +20,10 @@ KEYS_ORDER: Tuple[Tuple[str, Tuple[str, ...]], ...] = ( 'metadata', ( 'name', 'version', 'description', 'long_description', 'long_description...