Skip to content

Commit 01b5d24

Browse files
initial commit for issue 2918
1 parent cb2d7c7 commit 01b5d24

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

pyrefly/lib/alt/call.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -365,9 +365,15 @@ impl<'a, Ans: LookupAnswer> AnswersSolver<'a, Ans> {
365365
// If the class has an unknown base (e.g. inherits from an
366366
// unresolved name), it might have inherited `__call__` from
367367
// that base, so treat it as callable with implicit Any.
368+
//
369+
// `NotImplemented` is a singleton instance of `NotImplementedType`; it must
370+
// never be treated as callable even when stubs use `NotImplementedType(Any)`,
371+
// which would otherwise set `has_base_any` and hit this branch.
368372
None if self
369373
.get_metadata_for_class(cls.class_object())
370-
.has_base_any() =>
374+
.has_base_any()
375+
&& !cls.has_qname("types", "NotImplementedType")
376+
&& !cls.has_qname("builtins", "_NotImplementedType") =>
371377
{
372378
CallTargetLookup::Ok(Box::new(CallTarget::Any(AnyStyle::Implicit)))
373379
}
@@ -1029,10 +1035,7 @@ impl<'a, Ans: LookupAnswer> AnswersSolver<'a, Ans> {
10291035
&& meta.kind == FunctionKind::Dataclass
10301036
&& let Some(first_ty) = self.first_arg_type(args, errors)
10311037
{
1032-
let first_arg_range = args
1033-
.first()
1034-
.map(|a| a.range())
1035-
.unwrap_or(arguments_range);
1038+
let first_arg_range = args.first().map(|a| a.range()).unwrap_or(arguments_range);
10361039
self.map_over_union(&first_ty, |ty| {
10371040
if let Some((_, inner)) = self.unwrap_class_object_silently(ty) {
10381041
if let Type::ClassType(ct) = inner

pyrefly/lib/alt/class/class_metadata.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -390,10 +390,7 @@ impl<'a, Ans: LookupAnswer> AnswersSolver<'a, Ans> {
390390
errors,
391391
cls.range(),
392392
ErrorInfo::Kind(ErrorKind::BadClassDefinition),
393-
format!(
394-
"Cannot apply @dataclass to Enum class `{}`",
395-
cls.name()
396-
),
393+
format!("Cannot apply @dataclass to Enum class `{}`", cls.name()),
397394
);
398395
dataclass_metadata = None;
399396
}

pyrefly/lib/test/callable.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,3 +1449,13 @@ def after_func() -> None: ...
14491449
schedule(1000, after_func)
14501450
"#,
14511451
);
1452+
1453+
// Regression test for https://github.com/facebook/pyrefly/issues/2918
1454+
testcase!(
1455+
test_notimplemented_not_callable,
1456+
r#"
1457+
NotImplemented() # E: Expected a callable
1458+
NotImplemented("not yet done") # E: Expected a callable
1459+
raise NotImplementedError()
1460+
"#,
1461+
);

0 commit comments

Comments
 (0)