Skip to content

Commit ddb1bd6

Browse files
authored
chore: apply flake8 builtin rules (#248)
1 parent 7471a26 commit ddb1bd6

File tree

11 files changed

+102
-77
lines changed

11 files changed

+102
-77
lines changed

examples/connect/shiny-python/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
app_ui = ui.page_fluid(ui.output_text("text"), ui.output_data_frame("result"))
1717

1818

19-
def server(input: Inputs, output: Outputs, session: Session):
19+
def server(i: Inputs, o: Outputs, session: Session):
2020
"""
2121
Shiny for Python example application that shows user information and
2222
the first few rows from a table hosted in Databricks.

pyproject.toml

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,32 @@ docstring-code-format = true
4444
docstring-code-line-length = "dynamic"
4545

4646
[tool.ruff.lint]
47-
select = ["D", "F401", "I"]
47+
select = [
48+
# flake8-builtins
49+
# https://docs.astral.sh/ruff/rules/#flake8-builtins-a
50+
#
51+
# Check for builtin shadowing (i.e., naming a variable 'for', which is a builtin.)
52+
"A",
53+
54+
# pydocstyle
55+
# https://docs.astral.sh/ruff/rules/#pydocstyle-d
56+
# https://docs.astral.sh/ruff/faq/#does-ruff-support-numpy-or-google-style-docstrings
57+
#
58+
# Check docstring formatting. Many of these rules are intentionally ignored below.
59+
"D",
60+
61+
# pyflakes - unused-import
62+
# https://docs.astral.sh/ruff/rules/unused-import/
63+
#
64+
# Check for unused imports.
65+
"F401",
66+
67+
# isort
68+
# https://docs.astral.sh/ruff/rules/#isort-i
69+
#
70+
# Sort imports.
71+
"I"
72+
]
4873
ignore = [
4974
# NumPy style docstring convention with noted exceptions.
5075
# https://docs.astral.sh/ruff/faq/#does-ruff-support-numpy-or-google-style-docstrings
@@ -67,7 +92,7 @@ ignore = [
6792
'D415',
6893
'D416',
6994
'D417',
70-
'D418', # The Python Language Server can accomdate documentation for individual methods.
95+
'D418', # The Python Language Server can accomodate documentation for individual methods.
7196
# TODO(#135) resarch D418 and determine if we should continue ignoring it.
7297
]
7398

src/posit/connect/bundles.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -235,16 +235,16 @@ def __init__(
235235
super().__init__(params)
236236
self.content_guid = content_guid
237237

238-
def create(self, input: io.BufferedReader | bytes | str) -> Bundle:
238+
def create(self, archive: io.BufferedReader | bytes | str) -> Bundle:
239239
"""
240240
Create a bundle.
241241
242242
Create a bundle from a file or memory.
243243
244244
Parameters
245245
----------
246-
input : io.BufferedReader, bytes, or str
247-
Input archive for bundle creation. A 'str' type assumes a relative or absolute filepath.
246+
archive : io.BufferedReader, bytes, or str
247+
Archive for bundle creation. A 'str' type assumes a relative or absolute filepath.
248248
249249
Returns
250250
-------
@@ -273,14 +273,14 @@ def create(self, input: io.BufferedReader | bytes | str) -> Bundle:
273273
>>> bundle.create("bundle.tar.gz")
274274
None
275275
"""
276-
if isinstance(input, (io.BufferedReader, bytes)):
277-
data = input
278-
elif isinstance(input, str):
279-
with open(input, "rb") as file:
276+
if isinstance(archive, (io.BufferedReader, bytes)):
277+
data = archive
278+
elif isinstance(archive, str):
279+
with open(archive, "rb") as file:
280280
data = file.read()
281281
else:
282282
raise TypeError(
283-
f"create() expected argument type 'io.BufferedReader', 'bytes', or 'str', but got '{type(input).__name__}'"
283+
f"create() expected argument type 'io.BufferedReader', 'bytes', or 'str', but got '{type(archive).__name__}'"
284284
)
285285

286286
path = f"v1/content/{self.content_guid}/bundles"
@@ -314,20 +314,20 @@ def find_one(self) -> Bundle | None:
314314
bundles = self.find()
315315
return next(iter(bundles), None)
316316

317-
def get(self, id: str) -> Bundle:
317+
def get(self, uid: str) -> Bundle:
318318
"""Get a bundle.
319319
320320
Parameters
321321
----------
322-
id : str
322+
uid : str
323323
Identifier of the bundle to retrieve.
324324
325325
Returns
326326
-------
327327
Bundle
328328
The bundle with the specified ID.
329329
"""
330-
path = f"v1/content/{self.content_guid}/bundles/{id}"
330+
path = f"v1/content/{self.content_guid}/bundles/{uid}"
331331
url = self.url + path
332332
response = self.session.get(url)
333333
result = response.json()

src/posit/connect/cursors.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,17 @@ def fetch_pages(self) -> Generator[CursorPage, None, None]:
4545
------
4646
Generator[Page, None, None]
4747
"""
48-
next = None
48+
next_page = None
4949
while True:
50-
page = self.fetch_page(next)
50+
page = self.fetch_page(next_page)
5151
yield page
5252
cursors: dict = page.paging.get("cursors", {})
53-
next = cursors.get("next")
54-
if not next:
53+
next_page = cursors.get("next")
54+
if not next_page:
5555
# stop if a next page is not defined
5656
return
5757

58-
def fetch_page(self, next: str | None = None) -> CursorPage:
58+
def fetch_page(self, next_page: str | None = None) -> CursorPage:
5959
"""Fetch a page.
6060
6161
Parameters
@@ -69,7 +69,7 @@ def fetch_page(self, next: str | None = None) -> CursorPage:
6969
"""
7070
params = {
7171
**self.params,
72-
"next": next,
72+
"next": next_page,
7373
"limit": _MAX_PAGE_SIZE,
7474
}
7575
response = self.session.get(self.url, params=params)

src/posit/connect/permissions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,19 +149,19 @@ def find_one(self, *args, **kwargs) -> Permission | None:
149149
permissions = self.find(*args, **kwargs)
150150
return next(iter(permissions), None)
151151

152-
def get(self, id: str) -> Permission:
152+
def get(self, uid: str) -> Permission:
153153
"""Get a permission.
154154
155155
Parameters
156156
----------
157-
id : str
157+
uid : str
158158
The permission id.
159159
160160
Returns
161161
-------
162162
Permission
163163
"""
164-
path = f"v1/content/{self.content_guid}/permissions/{id}"
164+
path = f"v1/content/{self.content_guid}/permissions/{uid}"
165165
url = self.url + path
166166
response = self.session.get(url)
167167
return Permission(self.params, **response.json())

src/posit/connect/tasks.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,12 @@ def wait_for(self) -> None:
144144

145145
class Tasks(resources.Resources):
146146
@overload
147-
def get(self, id: str, first: int, wait: int) -> Task:
147+
def get(self, uid: str, first: int, wait: int) -> Task:
148148
"""Get a task.
149149
150150
Parameters
151151
----------
152-
id : str
152+
uid : str
153153
Task identifier.
154154
first : int, default 0
155155
Line to start output on.
@@ -163,12 +163,12 @@ def get(self, id: str, first: int, wait: int) -> Task:
163163
...
164164

165165
@overload
166-
def get(self, id: str, *args, **kwargs) -> Task:
166+
def get(self, uid: str, *args, **kwargs) -> Task:
167167
"""Get a task.
168168
169169
Parameters
170170
----------
171-
id : str
171+
uid : str
172172
Task identifier.
173173
174174
Returns
@@ -177,20 +177,20 @@ def get(self, id: str, *args, **kwargs) -> Task:
177177
"""
178178
...
179179

180-
def get(self, id: str, *args, **kwargs) -> Task:
180+
def get(self, uid: str, *args, **kwargs) -> Task:
181181
"""Get a task.
182182
183183
Parameters
184184
----------
185-
id : str
185+
uid : str
186186
Task identifier.
187187
188188
Returns
189189
-------
190190
Task
191191
"""
192192
params = dict(*args, **kwargs)
193-
path = f"v1/tasks/{id}"
193+
path = f"v1/tasks/{uid}"
194194
url = self.url + path
195195
response = self.session.get(url, params=params)
196196
result = response.json()

src/posit/connect/users.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,8 @@ def find_one(self, *args, **kwargs) -> User | None:
230230
)
231231
return next(users, None)
232232

233-
def get(self, id: str) -> User:
234-
url = self.url + f"v1/users/{id}"
233+
def get(self, uid: str) -> User:
234+
url = self.url + f"v1/users/{uid}"
235235
response = self.session.get(url)
236236
return User(
237237
self.params,

tests/posit/connect/test_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@
77
from .api import load_mock # type: ignore
88

99

10-
@pytest.fixture
10+
@pytest.fixture()
1111
def MockAuth():
1212
with patch("posit.connect.client.Auth") as mock:
1313
yield mock
1414

1515

16-
@pytest.fixture
16+
@pytest.fixture()
1717
def MockConfig():
1818
with patch("posit.connect.client.Config") as mock:
1919
yield mock
2020

2121

22-
@pytest.fixture
22+
@pytest.fixture()
2323
def MockSession():
2424
with patch("posit.connect.client.Session") as mock:
2525
yield mock

tests/posit/connect/test_env.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,10 @@ def test_find():
304304
content = c.content.get(guid)
305305

306306
# invoke
307-
vars = content.environment_variables.find()
307+
envvars = content.environment_variables.find()
308308

309309
# assert
310-
assert vars == ["TEST"]
310+
assert envvars == ["TEST"]
311311
assert mock_get_content.call_count == 1
312312
assert mock_get_environment.call_count == 1
313313

tests/posit/connect/test_permissions.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@ class TestPermissionDelete:
1515
@responses.activate
1616
def test(self):
1717
# data
18-
id = "94"
18+
uid = "94"
1919
content_guid = "f2f37341-e21d-3d80-c698-a935ad614066"
2020

2121
# behavior
2222
mock_delete = responses.delete(
23-
f"https://connect.example/__api__/v1/content/{content_guid}/permissions/{id}"
23+
f"https://connect.example/__api__/v1/content/{content_guid}/permissions/{uid}"
2424
)
2525

2626
# setup
2727
params = ResourceParameters(
2828
requests.Session(), Url("https://connect.example/__api__")
2929
)
3030
fake_permission = load_mock(
31-
f"v1/content/{content_guid}/permissions/{id}.json"
31+
f"v1/content/{content_guid}/permissions/{uid}.json"
3232
)
3333
permission = Permission(params, **fake_permission)
3434

@@ -43,7 +43,7 @@ class TestPermissionUpdate:
4343
@responses.activate
4444
def test_request_shape(self):
4545
# test data
46-
id = random.randint(0, 100)
46+
uid = random.randint(0, 100)
4747
content_guid = str(uuid.uuid4())
4848
principal_guid = str(uuid.uuid4())
4949
principal_type = "principal_type"
@@ -52,7 +52,7 @@ def test_request_shape(self):
5252

5353
# define api behavior
5454
responses.put(
55-
f"https://connect.example/__api__/v1/content/{content_guid}/permissions/{id}",
55+
f"https://connect.example/__api__/v1/content/{content_guid}/permissions/{uid}",
5656
json={
5757
# doesn't matter for this test
5858
},
@@ -77,7 +77,7 @@ def test_request_shape(self):
7777
)
7878
permission = Permission(
7979
params,
80-
id=id,
80+
id=uid,
8181
content_guid=content_guid,
8282
principal_guid=principal_guid,
8383
principal_type=principal_type,
@@ -94,18 +94,18 @@ def test_role_update(self):
9494
old_role = "owner"
9595
new_role = "viewer"
9696

97-
id = "94"
97+
uid = "94"
9898
content_guid = "f2f37341-e21d-3d80-c698-a935ad614066"
9999
fake_permission = load_mock(
100-
f"v1/content/{content_guid}/permissions/{id}.json"
100+
f"v1/content/{content_guid}/permissions/{uid}.json"
101101
)
102102
fake_permission.update(role=new_role)
103103

104104
# define api behavior
105-
id = random.randint(0, 100)
105+
uid = random.randint(0, 100)
106106
content_guid = str(uuid.uuid4())
107107
responses.put(
108-
f"https://connect.example/__api__/v1/content/{content_guid}/permissions/{id}",
108+
f"https://connect.example/__api__/v1/content/{content_guid}/permissions/{uid}",
109109
json=fake_permission,
110110
match=[
111111
matchers.json_params_matcher(
@@ -123,7 +123,7 @@ def test_role_update(self):
123123
requests.Session(), Url("https://connect.example/__api__")
124124
)
125125
permission = Permission(
126-
params, id=id, content_guid=content_guid, role=old_role
126+
params, id=uid, content_guid=content_guid, role=old_role
127127
)
128128

129129
# assert role change with respect to api response
@@ -164,13 +164,13 @@ class TestPermissionsCreate:
164164
@responses.activate
165165
def test(self):
166166
# data
167-
id = "94"
167+
uid = "94"
168168
content_guid = "f2f37341-e21d-3d80-c698-a935ad614066"
169169
principal_guid = str(uuid.uuid4())
170170
principal_type = "user"
171171
role = "owner"
172172
fake_permission = {
173-
**load_mock(f"v1/content/{content_guid}/permissions/{id}.json"),
173+
**load_mock(f"v1/content/{content_guid}/permissions/{uid}.json"),
174174
"principal_guid": principal_guid,
175175
"principal_type": principal_type,
176176
"role": role,
@@ -268,15 +268,15 @@ class TestPermissionsGet:
268268
@responses.activate
269269
def test(self):
270270
# data
271-
id = "94"
271+
uid = "94"
272272
content_guid = "f2f37341-e21d-3d80-c698-a935ad614066"
273273
fake_permission = load_mock(
274-
f"v1/content/{content_guid}/permissions/{id}.json"
274+
f"v1/content/{content_guid}/permissions/{uid}.json"
275275
)
276276

277277
# behavior
278278
responses.get(
279-
f"https://connect.example/__api__/v1/content/{content_guid}/permissions/{id}",
279+
f"https://connect.example/__api__/v1/content/{content_guid}/permissions/{uid}",
280280
json=fake_permission,
281281
)
282282

@@ -287,7 +287,7 @@ def test(self):
287287
permissions = Permissions(params, content_guid=content_guid)
288288

289289
# invoke
290-
permission = permissions.get(id)
290+
permission = permissions.get(uid)
291291

292292
# assert
293293
assert permission == fake_permission

0 commit comments

Comments
 (0)