Skip to content

Commit

Permalink
Context now inherits from dict. Would be nice to remove it
Browse files Browse the repository at this point in the history
  • Loading branch information
schloerke committed Nov 14, 2024
1 parent 04a5c22 commit c56d99a
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/posit/connect/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c56d99a

Please sign in to comment.