Skip to content

Commit d4efe30

Browse files
Enable reportPrivateUsage in basedpyright
1 parent 93eebf1 commit d4efe30

15 files changed

Lines changed: 42 additions & 39 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,6 @@ reportExplicitAny = false
214214
reportImplicitStringConcatenation = false
215215
reportMissingParameterType = false
216216
reportMissingTypeArgument = false
217-
reportPrivateUsage = false
218217
reportUnknownArgumentType = false
219218
reportUnknownMemberType = false
220219
reportUnknownVariableType = false
@@ -223,6 +222,7 @@ reportUnusedCallResult = false
223222

224223
[[tool.basedpyright.executionEnvironments]]
225224
root = "tests"
225+
reportPrivateUsage = false
226226
reportUnannotatedClassAttribute = false
227227
reportUnknownLambdaType = false
228228
reportUnknownParameterType = false

src/usethis/_backend/uv/call.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,9 @@ def _prepare_pyproject_write() -> None:
8282
if is_pyproject_toml and is_locked:
8383
ensure_pyproject_validity()
8484
PyprojectTOMLManager().write_file()
85-
PyprojectTOMLManager()._content = None # Basically a cache clear
85+
PyprojectTOMLManager().revert()
8686
elif not is_pyproject_toml and is_locked:
87-
# Similarly; cache clear
88-
PyprojectTOMLManager()._content = None
87+
PyprojectTOMLManager().revert()
8988
elif is_pyproject_toml:
9089
with PyprojectTOMLManager():
9190
ensure_pyproject_validity()

src/usethis/_core/tool.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ def _add_bitbucket_linter_steps_to_default() -> None:
244244
tools: list[Tool] = [PyprojectFmtTool(), DeptryTool(), RuffTool()]
245245
for tool in tools:
246246
if tool.is_used():
247-
tool._unconditional_update_bitbucket_steps()
247+
tool.unconditional_update_bitbucket_steps()
248248

249249

250250
def _remove_bitbucket_linter_steps_from_default() -> None:
@@ -441,7 +441,7 @@ def use_ruff(
441441
# See docstring. Basically, `usethis docstyle` manages the pydocstyle rules,
442442
# so we want to allow the user to subsequently call `usethis tool ruff` and
443443
# still get non-minimal default rules.
444-
all(tool._is_pydocstyle_rule(rule) for rule in tool.selected_rules())
444+
all(tool.is_pydocstyle_rule(rule) for rule in tool.selected_rules())
445445
# Another situation where we add default rules is when there are no rules
446446
# selected yet (and we haven't explicitly been requested to add minimal config).
447447
or not tool.selected_rules()

src/usethis/_file/manager.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ def commit(self, document: DocumentT) -> None:
109109
self._validate_lock()
110110
self._content = document
111111

112+
def revert(self) -> None:
113+
"""Clear the stored document without writing to disk."""
114+
self._content = None
115+
112116
def write_file(self) -> None:
113117
"""Write the stored document to disk if there are changes."""
114118
self._validate_lock()

src/usethis/_file/merge.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
T = TypeVar("T", bound=MutableMapping[Any, Any])
77

88

9-
def _deep_merge(target: T, source: MutableMapping[Any, Any]) -> T:
9+
def deep_merge(target: T, source: MutableMapping[Any, Any]) -> T:
1010
"""Recursively merge source into target in place, returning target.
1111
1212
For keys present in both mappings, if both values are mappings the merge is
@@ -18,7 +18,7 @@ def _deep_merge(target: T, source: MutableMapping[Any, Any]) -> T:
1818
and isinstance(target[key], MutableMapping)
1919
and isinstance(value, MutableMapping)
2020
):
21-
_deep_merge(target[key], value)
21+
deep_merge(target[key], value)
2222
else:
2323
target[key] = value
2424
return target

src/usethis/_file/pyproject_toml/valid.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def _ensure_project_name(project: Table) -> None:
6363
name = get_project_name_from_dir()
6464

6565
tick_print(f"Setting project name to '{name}' in 'pyproject.toml'.")
66-
if project._value:
67-
project._value._insert_at(0, "name", name)
66+
if project.value:
67+
project._value._insert_at(0, "name", name) # pyright: ignore[reportPrivateUsage]
6868
else:
6969
project["name"] = name

src/usethis/_file/toml/io_.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
UnexpectedFileIOError,
1919
UnexpectedFileOpenError,
2020
)
21-
from usethis._file.merge import _deep_merge
21+
from usethis._file.merge import deep_merge
2222
from usethis._file.print_ import print_keys
2323
from usethis._file.toml.errors import (
2424
TOMLDecodeError,
@@ -396,7 +396,7 @@ def _set_value_in_existing(
396396
contents = value
397397
for key in reversed(keys):
398398
contents = {key: contents}
399-
toml_document = _deep_merge(toml_document, contents)
399+
toml_document = deep_merge(toml_document, contents)
400400
assert isinstance(toml_document, TOMLDocument)
401401
else:
402402
# Note that this alternative logic is just to avoid a bug:
@@ -411,7 +411,7 @@ def _set_value_in_existing(
411411
# https://github.com/usethis-python/usethis-python/issues/558
412412

413413
placeholder = {keys[0]: {keys[1]: {}}}
414-
toml_document = _deep_merge(toml_document, placeholder)
414+
toml_document = deep_merge(toml_document, placeholder)
415415

416416
contents = value
417417
for key in reversed(unshared_keys[1:]):

src/usethis/_file/yaml/io_.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
UnexpectedFileIOError,
2222
UnexpectedFileOpenError,
2323
)
24-
from usethis._file.merge import _deep_merge
24+
from usethis._file.merge import deep_merge
2525
from usethis._file.print_ import print_keys
2626
from usethis._file.yaml.errors import (
2727
UnexpectedYAMLIOError,
@@ -323,7 +323,7 @@ def extend_list(self, *, keys: Sequence[Key], values: Sequence[Any]) -> None:
323323
for key in reversed(keys):
324324
new_content = {key: new_content}
325325
assert isinstance(new_content, dict)
326-
content = _deep_merge(content, new_content)
326+
content = deep_merge(content, new_content)
327327
assert isinstance(content, dict)
328328
else:
329329
TypeAdapter(dict).validate_python(p_parent)
@@ -400,7 +400,7 @@ def _set_value_in_existing(
400400
contents = value
401401
for key in reversed(keys):
402402
contents = {key: contents}
403-
content = _deep_merge(content, contents)
403+
content = deep_merge(content, contents)
404404

405405

406406
def _validate_keys(keys: Sequence[Key]) -> list[str]:

src/usethis/_integrations/ci/bitbucket/cache.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ def add_caches(cache_by_name: dict[str, schema.Cache]) -> None:
2828

2929
mgr = BitbucketPipelinesYAMLManager()
3030
model = mgr.model_validate()
31-
_add_caches_via_model(cache_by_name, model=model)
31+
add_caches_via_model(cache_by_name, model=model)
3232
mgr.commit_model(model)
3333

3434

35-
def _add_caches_via_model(
35+
def add_caches_via_model(
3636
cache_by_name: dict[str, schema.Cache], *, model: schema.PipelinesConfiguration
3737
) -> None:
3838
if model.definitions is None:

src/usethis/_integrations/ci/bitbucket/steps.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
ScriptItemAnchor,
1616
anchor_name_from_script_item,
1717
)
18-
from usethis._integrations.ci.bitbucket.cache import _add_caches_via_model, remove_cache
18+
from usethis._integrations.ci.bitbucket.cache import add_caches_via_model, remove_cache
1919
from usethis._integrations.ci.bitbucket.errors import (
2020
UnexpectedImportPipelineError,
2121
)
@@ -412,7 +412,7 @@ def _add_step_caches_via_model(
412412
)
413413
raise NotImplementedError(msg) from None
414414
cache_by_name[name] = cache
415-
_add_caches_via_model(cache_by_name, model=model)
415+
add_caches_via_model(cache_by_name, model=model)
416416

417417

418418
def bitbucket_steps_are_equivalent(

0 commit comments

Comments
 (0)