Skip to content

Commit

Permalink
add tests for an issue that i accidentally fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
DetachHead committed Dec 1, 2024
1 parent 56e2825 commit 2548f1b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,14 @@ def takes_arg(value: object) -> TypeIs[Callable[[int], None]]: ...

def _(value: Callable[[], None] | Callable[[int], None]):
if takes_arg(value):
assert_type(value, Callable[[int], None])
assert_type(value, Callable[[int], None])

# test for an upstream bug that i accidentally fixed
# https://github.com/DetachHead/basedpyright/issues/452
class Bar:
...
class Baz(Bar):
def __call__(self): ...
def _[T, **P](value: Callable[P, T]):
if isinstance(value, Bar):
reveal_type(value)
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,15 @@ def takes_arg(value: object) -> TypeIs[Callable[[int], None]]: ...

def _(value: Callable[[], None] | Callable[[int], None]):
if takes_arg(value):
assert_type(value, Callable[[int], None])
assert_type(value, Callable[[int], None])


# test for an upstream bug that i accidentally fixed
# https://github.com/DetachHead/basedpyright/issues/452
class Bar:
...
class Baz(Bar):
def __call__(self): ...
def _[T, **P](value: Callable[P, T]):
if isinstance(value, Bar):
pass
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ describe('narrowing type vars using their bounds', () => {
const analysisResults = typeAnalyzeSampleFiles(['typeNarrowingUsingBounds.py'], configOptions);
validateResultsButBased(analysisResults, {
errors: [],
infos: [{ line: 124, message: 'Type of "f" is "<subclass of Callable and staticmethod[..., object]>"' }],
infos: [
{ line: 124, message: 'Type of "f" is "<subclass of Callable and staticmethod[..., object]>"' },
{ line: 152, message: 'Type of "value" is "<subclass of Callable and Bar>"' },
],
});
});
test('disabled', () => {
Expand All @@ -135,7 +138,7 @@ describe('narrowing type vars using their bounds', () => {
configOptions.diagnosticRuleSet.strictGenericNarrowing = false;
const analysisResults = typeAnalyzeSampleFiles(['typeNarrowingUsingBoundsDisabled.py'], configOptions);
validateResultsButBased(analysisResults, {
errors: [],
hints: [{ line: 151, code: DiagnosticRule.reportUnreachable }],
});
});
});

0 comments on commit 2548f1b

Please sign in to comment.