Skip to content

Commit

Permalink
stubber: Docstubs - Fix/undo removal of positional only /) from par…
Browse files Browse the repository at this point in the history
…ameters

Signed-off-by: Jos Verlinde <Jos.Verlinde@microsoft.com>
  • Loading branch information
Josverl committed Aug 25, 2024
1 parent 4a5a79a commit 1ee612e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/stubber/rst/lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ class Fix:
"machine.ADC": ["ATTN_0DB:int = ..."], # uses Pin
"machine.RTC": ["from machine import IDLE"], # uses Pin
"machine.UART": ["from machine import IDLE"], # uses Pin
"network": ["from abc import ABC"], # for AbstractNIC
"network": ["from typing import Protocol"], # for AbstractNIC
"rp2": ["from .PIO import PIO"], #
"pyb": ["from .UART import UART"], # uses Pin
"pyb.Switch": ["from .Pin import Pin"], # uses Pin
Expand All @@ -269,7 +269,10 @@ class Fix:
Fix(r"\**", "*"), # change weirdly written wildcards \* --> *
Fix(r"/*", "*"), # change weirdly written wildcards /* --> *
Fix(r"**", "*"), # change weirdly written wildcards ** --> *
Fix(r"/)", ")"), # strange terminator in machine.USBDevice `USBDevice.active(self, [value] /)`
# do not remove / , this indicates positional only notation before the ,/
Fix(r"]/)", "],/)"),
Fix(r"None/)", "None,/)"),
# do not remove / , this indicates positional only notation before the ,/
Fix("'param'", "param"), # loose notation in documentation
# illegal keywords
Fix(
Expand Down Expand Up @@ -545,7 +548,7 @@ class Fix:
# array
"array": "List",
# network
"AbstractNIC": "ABC",
"AbstractNIC": "Protocol",
}


Expand Down
7 changes: 5 additions & 2 deletions tests/rst/test_rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,11 @@ def test_rst_parse_class_10(line: str):
# ESPNow extra notation
("ESPNow.config('param') (ESP32 only)", "ESPNow.config(param)"),
# machine.USBDevice
# Extranous / `USBDevice.active(self, [value] /)`
("USBDevice.active(self, [value]/)", "USBDevice.active(self, value: Optional[Any]=None)"),
# Positional Only indicator should not be removed / `USBDevice.active(self, [value] /)`
(
"USBDevice.active(self, [value]/)",
"USBDevice.active(self, value: Optional[Any]=None,/)",
),
],
)
def test_fix_param(param_in, expected):
Expand Down

0 comments on commit 1ee612e

Please sign in to comment.