Skip to content

Commit 40c05d3

Browse files
authored
Merge branch 'master' into minor-refactorings
2 parents fe15b1a + 8e61a68 commit 40c05d3

File tree

21 files changed

+320
-126
lines changed

21 files changed

+320
-126
lines changed

.all-contributorsrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,15 @@
555555
"contributions": [
556556
"code"
557557
]
558+
},
559+
{
560+
"login": "sandratsy",
561+
"name": "Sandra Tan Shi Yun",
562+
"avatar_url": "https://avatars.githubusercontent.com/u/26302933?v=4",
563+
"profile": "https://github.com/sandratsy",
564+
"contributions": [
565+
"code"
566+
]
558567
}
559568
],
560569
"projectName": "rope",

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ __pycache__/
1010
.Python
1111
build/
1212
develop-eggs/
13-
dist/
13+
/dist/
1414
downloads/
1515
eggs/
1616
.eggs/

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# **Upcoming release**
22

3+
- Check for ast.Attributes when finding occurrences in fstrings (@sandratsy)
4+
- #777, #698 add validation to refuse Rename refactoring to a python keyword
35
- #730 Match on module aliases for autoimport suggestions
6+
- #755 Remove dependency on `build` package being installed while running tests
47

58
# Release 1.12.0
69

CONTRIBUTORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
8383
<td align="center" valign="top" width="14.28%"><a href="https://bamboolib.8080labs.com"><img src="https://avatars.githubusercontent.com/u/13402027?v=4?s=100" width="100px;" alt="Tobias Krabel"/><br /><sub><b>Tobias Krabel</b></sub></a><br /><a href="https://github.com/python-rope/rope/commits?author=tkrabel" title="Code">💻</a></td>
8484
<td align="center" valign="top" width="14.28%"><a href="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/MrBago"><img src="https://avatars.githubusercontent.com/u/223219?v=4?s=100" width="100px;" alt="Bago Amirbekian"/><br /><sub><b>Bago Amirbekian</b></sub></a><br /><a href="https://github.com/python-rope/rope/commits?author=MrBago" title="Code">💻</a></td>
8585
<td align="center" valign="top" width="14.28%"><a href="http://mender.ai"><img src="https://avatars.githubusercontent.com/u/3324?v=4?s=100" width="100px;" alt="Ray Myers"/><br /><sub><b>Ray Myers</b></sub></a><br /><a href="https://github.com/python-rope/rope/commits?author=raymyers" title="Code">💻</a></td>
86+
<td align="center" valign="top" width="14.28%"><a href="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/sandratsy"><img src="https://avatars.githubusercontent.com/u/26302933?v=4?s=100" width="100px;" alt="Sandra Tan Shi Yun"/><br /><sub><b>Sandra Tan Shi Yun</b></sub></a><br /><a href="https://github.com/python-rope/rope/commits?author=sandratsy" title="Code">💻</a></td>
8687
</tr>
8788
</tbody>
8889
</table>

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
include README.rst COPYING setup.py MANIFEST.in CHANGELOG.md
1+
include README.rst COPYING setup.py MANIFEST.in CHANGELOG.md ropetest-package-fixtures/external_fixturepkg/dist/external_fixturepkg-1.0.0-py3-none-any.whl ropetest-package-fixtures/external_fixturepkg/dist/external_fixturepkg-1.0.0.tar.gz
22
recursive-include rope *.py
33
recursive-include docs *.rst
44
recursive-include ropetest *.py

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ profile = "black"
8787

8888
[tool.pytest.ini_options]
8989

90+
testpaths = "ropetest"
9091
python_files = [
9192
"*test.py",
9293
"__init__.py",

rope/contrib/autoimport/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def get_package_source(
5454
if "site-packages" in package.parts:
5555
return Source.SITE_PACKAGE
5656
if sys.version_info < (3, 10, 0):
57-
if str(package).startswith(sys.prefix):
57+
if str(package).startswith(sys.base_prefix):
5858
return Source.STANDARD
5959
else:
6060
if name in sys.stdlib_module_names:

rope/refactor/occurrences.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
import contextlib
3939
import re
40+
from typing import Iterator
4041

4142
from rope.base import (
4243
ast,
@@ -319,7 +320,7 @@ def __init__(self, name, docs=False):
319320
)
320321
self.pattern = self._get_occurrence_pattern(self.name)
321322

322-
def find_offsets(self, source):
323+
def find_offsets(self, source: str) -> Iterator[int]:
323324
if not self._fast_file_query(source):
324325
return
325326
if self.docs:
@@ -328,22 +329,25 @@ def find_offsets(self, source):
328329
searcher = self._re_search
329330
yield from searcher(source)
330331

331-
def _re_search(self, source):
332+
def _re_search(self, source: str) -> Iterator[int]:
332333
for match in self.pattern.finditer(source):
333334
if match.groupdict()["occurrence"]:
334335
yield match.start("occurrence")
335336
elif match.groupdict()["fstring"]:
336337
f_string = match.groupdict()["fstring"]
337-
for occurrence_node in self._search_in_f_string(f_string):
338-
yield match.start("fstring") + occurrence_node.col_offset
338+
for offset in self._search_in_f_string(f_string):
339+
yield match.start("fstring") + offset
339340

340-
def _search_in_f_string(self, f_string):
341+
def _search_in_f_string(self, f_string: str) -> Iterator[int]:
341342
tree = ast.parse(f_string)
342343
for node in ast.walk(tree):
343344
if isinstance(node, ast.Name) and node.id == self.name:
344-
yield node
345+
yield node.col_offset
346+
elif isinstance(node, ast.Attribute) and node.attr == self.name:
347+
assert node.end_col_offset is not None
348+
yield node.end_col_offset - len(self.name)
345349

346-
def _normal_search(self, source):
350+
def _normal_search(self, source: str) -> Iterator[int]:
347351
current = 0
348352
while True:
349353
try:

rope/refactor/rename.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import warnings
2+
from keyword import iskeyword
23

34
from rope.base import (
45
codeanalyze,
@@ -105,6 +106,7 @@ def unsure_func(value=unsure):
105106
resources = [self.resource]
106107
if resources is None:
107108
resources = self.project.get_python_files()
109+
self.validate_changes(new_name)
108110
changes = ChangeSet(f"Renaming <{self.old_name}> to <{new_name}>")
109111
finder = occurrences.create_finder(
110112
self.project,
@@ -128,6 +130,16 @@ def unsure_func(value=unsure):
128130
self._rename_module(resource, new_name, changes)
129131
return changes
130132

133+
def validate_changes(
134+
self,
135+
new_name: str,
136+
**_unused,
137+
):
138+
if iskeyword(new_name):
139+
raise exceptions.RefactoringError(
140+
f"Invalid refactoring target name. '{new_name}' is a Python keyword."
141+
)
142+
131143
def _is_allowed_to_move(self, resources, resource):
132144
if resource.is_folder():
133145
try:
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# example_project
2+
3+
Just an example project for testing rope.
4+
5+
6+
To build this package, run:
7+
8+
```bash
9+
$ python -m build
10+
```
11+
12+
This generates packages in `dist` folder.

0 commit comments

Comments
 (0)