Skip to content

Commit

Permalink
[pyright] [core] _core/definitions/scoped_resources_builder (#11698)
Browse files Browse the repository at this point in the history
### Summary & Motivation

Eliminates some type errors on access to the `Resource` class. AFAICT,
the `Resource` class is not constructed anywhere other than in
`ScopedResourceBuilder`, where there are dynamically generated
subclasses of it. All of these subclasses have an identical
`__getattr__` method-- so moving this into `Resource` provides
equivalent functionality, while also solving type errors from accessing
attributes on `Resource` objects.

### How I Tested These Changes

BK
  • Loading branch information
smackesey committed Jan 18, 2023
1 parent 1195798 commit 4c3f099
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# See: https://github.com/python/mypy/issues/7281

from collections import namedtuple
from typing import AbstractSet, Mapping, NamedTuple, Optional
from typing import AbstractSet, Any, Mapping, NamedTuple, Optional

import dagster._check as check
from dagster._core.errors import DagsterUnknownResourceError
Expand All @@ -25,6 +25,9 @@ class Resources:
provides a workaround.
"""

def __getattr__(self, name: str) -> Any:
raise DagsterUnknownResourceError(name)


class ScopedResourcesBuilder(
NamedTuple(
Expand Down Expand Up @@ -85,8 +88,7 @@ class _ScopedResourcesContainsGenerator(
Resources,
IContainsGenerator,
):
def __getattr__(self, attr):
raise DagsterUnknownResourceError(attr)
...

return _ScopedResourcesContainsGenerator(**resource_instance_dict) # type: ignore[call-arg]

Expand All @@ -96,7 +98,6 @@ class _ScopedResources(
namedtuple("_ScopedResources", list(resource_instance_dict.keys())), # type: ignore[misc]
Resources,
):
def __getattr__(self, attr):
raise DagsterUnknownResourceError(attr)
...

return _ScopedResources(**resource_instance_dict) # type: ignore[call-arg]
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,7 @@ def get_logs_for_all_runs_by_log_id(
results = conn.execute(query).fetchall()

events = {}
record_id = None
try:
for (
record_id,
Expand Down

0 comments on commit 4c3f099

Please sign in to comment.