File tree Expand file tree Collapse file tree 1 file changed +76
-0
lines changed Expand file tree Collapse file tree 1 file changed +76
-0
lines changed Original file line number Diff line number Diff line change @@ -483,3 +483,79 @@ try:
483
483
except Exception as typing:
484
484
pass
485
485
[builtins fixtures/exception.pyi]
486
+
487
+ [case testRedefiningUnderscoreFunctionIsntAnError]
488
+ def _(arg):
489
+ pass
490
+
491
+ def _(arg):
492
+ pass
493
+
494
+ [case testTypeErrorsInUnderscoreFunctionsReported]
495
+ def _(arg: str):
496
+ x = arg + 1 # E: Unsupported left operand type for + ("str")
497
+
498
+ def _(arg: int) -> int:
499
+ return 'a' # E: Incompatible return value type (got "str", expected "int")
500
+
501
+ [case testCallingUnderscoreFunctionIsNotAllowed]
502
+ def _(arg: str) -> None:
503
+ pass
504
+
505
+ def _(arg: int) -> int:
506
+ return arg
507
+
508
+ _('a') # E: Calling function named "_" is not allowed
509
+
510
+ y = _(5) # E: Calling function named "_" is not allowed
511
+
512
+ [case testFunctionStillTypeCheckedWhenAliasedAsUnderscoreDuringImport]
513
+ from a import f as _
514
+
515
+ _(1) # E: Argument 1 to "f" has incompatible type "int"; expected "str"
516
+ reveal_type(_('a')) # N: Revealed type is "builtins.str"
517
+
518
+ [file a.py]
519
+ def f(arg: str) -> str:
520
+ return arg
521
+
522
+ [case testCallToFunctionStillTypeCheckedWhenAssignedToUnderscoreVariable]
523
+ from a import g
524
+ _ = g
525
+
526
+ _('a') # E: Argument 1 has incompatible type "str"; expected "int"
527
+ reveal_type(_(1)) # N: Revealed type is "builtins.int"
528
+
529
+ [file a.py]
530
+ def g(arg: int) -> int:
531
+ return arg
532
+
533
+ [case testRedefiningUnderscoreFunctionWithDecoratorWithUnderscoreFunctionsNextToEachOther]
534
+ def dec(f):
535
+ return f
536
+
537
+ @dec
538
+ def _(arg):
539
+ pass
540
+
541
+ @dec
542
+ def _(arg):
543
+ pass
544
+
545
+ [case testRedefiningUnderscoreFunctionWithDecoratorInDifferentPlaces]
546
+ def dec(f):
547
+ return f
548
+
549
+ def dec2(f):
550
+ return f
551
+
552
+ @dec
553
+ def _(arg):
554
+ pass
555
+
556
+ def f(arg):
557
+ pass
558
+
559
+ @dec2
560
+ def _(arg):
561
+ pass
You can’t perform that action at this time.
0 commit comments