Skip to content

feat: Temporarily negate ProjectAuthenticationWarning when using Project.is_shared()#610

Merged
faretek1 merged 3 commits intoTimMcCool:mainfrom
Boss-1s:chore
May 10, 2026
Merged

feat: Temporarily negate ProjectAuthenticationWarning when using Project.is_shared()#610
faretek1 merged 3 commits intoTimMcCool:mainfrom
Boss-1s:chore

Conversation

@Boss-1s
Copy link
Copy Markdown
Contributor

@Boss-1s Boss-1s commented May 9, 2026

Solves issue #592

Changes

  • Negated Project.get_project's ProjectAuthenticationWarning using warnings.catch_warnings()

Tests

Tested in CPython 3.12.1 REPL

Python 3.12.1 (main, Mar 11 2026, 12:17:56) [GCC 13.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
Ctrl click to launch VS Code Native REPL
>>> import scratchattach
>>> print(scratchattach.Project(id=103).is_shared())
False
>>> print(scratchattach.Project(id=104).is_shared())
True
>>> print(scratchattach.get_project(103))
/workspaces/scratchattach/src/scratchattach/scratchattach/site/project.py:828: ProjectAuthenticationWarning: For methods that require authentication, use session.connect_project instead of get_project.
If you want to remove this warning, use `warnings.filterwarnings('ignore', category=scratchattach.ProjectAuthenticationWarning)`.
To ignore all warnings of the type GetAuthenticationWarning, which includes this warning, use `warnings.filterwarnings('ignore', category=scratchattach.GetAuthenticationWarning)`.
  warnings.warn(
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/workspaces/scratchattach/src/scratchattach/scratchattach/site/project.py", line 836, in get_project
    return commons._get_object("id", project_id, Project, exceptions.ProjectNotFound)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/scratchattach/src/scratchattach/scratchattach/utils/commons.py", line 163, in _get_object
    raise e
  File "/workspaces/scratchattach/src/scratchattach/scratchattach/utils/commons.py", line 157, in _get_object
    raise NotFoundException
scratchattach.utils.exceptions.ProjectNotFound
>>> print(scratchattach.Project(id=104).is_shared())
True
>>> print(scratchattach.get_project(104))
/workspaces/scratchattach/src/scratchattach/scratchattach/site/project.py:828: ProjectAuthenticationWarning: For methods that require authentication, use session.connect_project instead of get_project.
If you want to remove this warning, use `warnings.filterwarnings('ignore', category=scratchattach.ProjectAuthenticationWarning)`.
To ignore all warnings of the type GetAuthenticationWarning, which includes this warning, use `warnings.filterwarnings('ignore', category=scratchattach.GetAuthenticationWarning)`.
  warnings.warn(
-P 104 (Weekend)
>>> exit()

Boss-1s added 2 commits May 8, 2026 21:59
Signed-off-by: Boss_1s <95505913+Boss-1s@users.noreply.github.com>
Signed-off-by: Boss_1s <95505913+Boss-1s@users.noreply.github.com>
@faretek1
Copy link
Copy Markdown
Collaborator

This does work and is probably the simplest way to make it work

@faretek1 faretek1 requested a review from TheCommCraft May 10, 2026 12:09
@TheCommCraft TheCommCraft requested a review from faretek1 May 10, 2026 13:01
p = get_project(self.id)
return isinstance(p, Project)
except exceptions.ProjectNotFound:
response = requests.get(f"https://api.scratch.mit.edu/projects/{self.id}")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use self.update_api and self.update_method here although this isn't technically an update method so maybe it should be decoupled. But this is fine

@faretek1 faretek1 merged commit 903e882 into TimMcCool:main May 10, 2026
1 check failed
@Boss-1s Boss-1s deleted the chore branch May 10, 2026 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants