From c56d99ad1b13ebbe7c8fb44df32361e0506014c8 Mon Sep 17 00:00:00 2001 From: Barret Schloerke Date: Thu, 14 Nov 2024 05:20:26 -0500 Subject: [PATCH] Context now inherits from `dict`. Would be nice to remove it --- src/posit/connect/context.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/posit/connect/context.py b/src/posit/connect/context.py index 1e275838..0beb0105 100644 --- a/src/posit/connect/context.py +++ b/src/posit/connect/context.py @@ -27,7 +27,28 @@ def wrapper(instance: ContextManager, *args, **kwargs): return decorator -class Context: +# Big mystery: `Context` is a subclass of `dict`. However, this is unnecessary. +# BUT, when `dict` is removed, the following errors occur: +# ``` +# uv run pyright +# /Users/barret/Documents/git/rstudio/posit-sdk-py/posit-sdk-py.nosync/src/posit/connect/client.py +# /Users/barret/Documents/git/rstudio/posit-sdk-py/posit-sdk-py.nosync/src/posit/connect/client.py:274:25 - error: Argument of type "Context" cannot be assigned to parameter "iterable" of type "Iterable[Package]" in function "__new__" +# "Context" is incompatible with protocol "Iterable[Package]" +# "__iter__" is not present (reportArgumentType) +# /Users/barret/Documents/git/rstudio/posit-sdk-py/posit-sdk-py.nosync/src/posit/connect/jobs.py +# /Users/barret/Documents/git/rstudio/posit-sdk-py/posit-sdk-py.nosync/src/posit/connect/jobs.py:302:21 - error: Argument of type "ContentItemContext" cannot be assigned to parameter "iterable" of type "Iterable[Job]" in function "__new__" +# "ContentItemContext" is incompatible with protocol "Iterable[Job]" +# "__iter__" is not present (reportArgumentType) +# /Users/barret/Documents/git/rstudio/posit-sdk-py/posit-sdk-py.nosync/src/posit/connect/packages.py +# /Users/barret/Documents/git/rstudio/posit-sdk-py/posit-sdk-py.nosync/src/posit/connect/packages.py:102:32 - error: Argument of type "ContentItemContext" cannot be assigned to parameter "iterable" of type "Iterable[ContentPackage]" in function "__new__" +# "ContentItemContext" is incompatible with protocol "Iterable[ContentPackage]" +# "__iter__" is not present (reportArgumentType) +# 3 errors, 0 warnings, 0 informations +# ``` +# This is a mystery because `Context` is not used as an iterable in the codebase. + + +class Context(dict): def __init__(self, session: requests.Session, url: Url): self.session = session self.url = url