Skip to content

Make model.BaseBody accept Generic parameters - #4766

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

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

Conversation

@Serhiy1

@Serhiy1 Serhiy1 commented May 13, 2023 •

Copy link
Copy Markdown
Contributor
  • Body sub classes pass in correct types
  • Those types are used with @copy_signature to type the create_xxx methods
  • Added correctly typed body entries for running.TestCase and result.TestCase

Examples of the PR working
image

image

Unfortunately, One side effect of this PR is, that Pyright believes that Body.register methods are cyclical dependencies.

image

@Serhiy1
Serhiy1 force-pushed the dev/type-hinting branch from 61909ff to f2af189 Compare May 13, 2023 16:07
- `Body` sub classes pass in correct types
-  Those types are used with @copy_signature to type the `create_xxx` methods
-  Added correctly typed `body` entries for `running.TestCase` and `result.TestCase`
@Serhiy1
Serhiy1 force-pushed the dev/type-hinting branch from f2af189 to 657774a Compare May 13, 2023 16:08

@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.

Looks awesome! Can this still be simplified a bit by removing that one if TYPE_CHECKING?

Comment thread src/robot/model/body.py Outdated
break_class: Type[B] = KnownAtRuntime
message_class: Type[M] = KnownAtRuntime
error_class: Type[E] = KnownAtRuntime
else:

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.

Is if TYPE_CHECKING still needed here? Isn't Type[X] = KnownAtRuntime always available?

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

class Body(BaseBody):
class Body(BaseBody["Keyword", "For", "While", "If", "Try", "Return", "Continue",
"Break", "Message", "Error"]):

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.

I'm totally nitpicking, but we've generally used single quotes around strings when possible.

@pekkaklarck
pekkaklarck merged commit c706156 into robotframework:master May 13, 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