Skip to content

Enhance model.branches and result.Iterations typing - #4767

Merged
pekkaklarck merged 5 commits into
robotframework:masterfrom
Serhiy1:dev/type-hinting
May 22, 2023
Merged

pekkaklarck merged 5 commits into
robotframework:masterfrom
Serhiy1:dev/type-hinting

Conversation

@Serhiy1

@Serhiy1 Serhiy1 commented May 14, 2023

Copy link
Copy Markdown
Contributor

re-named model.Branches to model.BaseBranches

model.BaseBranches now takes an additional BranchType type parameter

result.Iterations now takes an additional IterationType parameter

If branch
image

try branch
image

for Iteration
image

while Iteration
image

Serhiy1 added 2 commits May 14, 2023 10:34
model.branches now takes an additional `branchtype` type parameter  

result.iterations now takes an additional `iterationtype` parameter

@pekkaklarck pekkaklarck left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See inline comments.

Comment thread src/robot/model/body.py Outdated
B = TypeVar('B', bound='Break')
M = TypeVar('M', bound='Message')
E = TypeVar('E', bound='Error')
BT = TypeVar('BT', 'IfBranch', 'TryBranch')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. TypeVar('X', bound=xxx) and TypeVar('X', xxx) have different semantic. I believe this should be TypeVar('BT', bound='IfBranch|TryBranch'). If not, then bound probably should be removed from others as well.
  2. Perhaps TI, from first letters of TryBranch and IfBranch, would be better name than BT. It would also be better than IT that looks like a short version of Iteration.

Comment thread src/robot/model/control.py Outdated


class Branches(BaseBranches['Keyword', 'For', 'While', 'If', 'Try', 'Return', 'Continue',
'Break', 'Message', 'Error', BT]):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Second row of the class declaration is misaligned.

Comment thread src/robot/result/model.py Outdated

class Branches(model.Branches):
class Branches(model.BaseBranches['Keyword', 'For', 'While', 'If', 'Try', 'Return',
'Continue', 'Break', 'Message', 'Error', BT]):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why BT is used here instead of 'IfBranch', 'TryBranch'?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The final parameter is passed in on the If and Try class

branch_class = IfBranch
branches_class = Branches[branch_class]
branch_class = TryBranch
branches_class = Branches[branch_class]

Comment thread src/robot/model/control.py Outdated
if TYPE_CHECKING:
from robot.model import Keyword, Message

BT = TypeVar('BT', 'IfBranch', 'TryBranch')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See earlier comments about bound usage and naming.

Comment thread src/robot/result/model.py Outdated
from .suiteteardownfailed import SuiteTeardownFailed, SuiteTeardownFailureHandler

BT = TypeVar('BT', 'IfBranch', 'TryBranch')
IT = TypeVar('IT', 'ForIteration', 'WhileIteration')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See earlier comments about bound usage and naming. If we'd use TI instead of BT, then IT here could be FW or WF. Perhaps the latter would be better because the former looks like an abbreviation of Framework.

@Serhiy1
Serhiy1 force-pushed the dev/type-hinting branch from e20b6f2 to 07229e0 Compare May 22, 2023 14:27
@pekkaklarck
pekkaklarck merged commit e253e6a into robotframework:master May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants