Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Add and use type annotations for urwid Text markups #1101

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Ezio-Sarthak
Copy link
Member

@Ezio-Sarthak Ezio-Sarthak commented Jul 27, 2021

What does this PR do?
Adds and uses type annotations for urwid.Text markups.

Tested?

  • Manually
  • Existing tests (adapted, if necessary)
  • New tests added (for any new behavior)
  • Passed linting & tests (each commit)

Commit flow

  • refactor: urwid_types: Add type annotation for urwid.Text markups.
  • refactor: core: Use type annotation for urwid text markups.
  • refactor: ui: Use type annotation for urwid text markups.
  • refactor: boxes: Use type annotation for urwid text markups.
  • refactor: views: Use type annotation for urwid text markups.

Notes & Questions

Interactions

Visual changes

This commit adds a general annotation for urwid.Text markup content.
Since the urwid markup is used almost throughout the UI part of the
codebase, it would be nice to annotate it as we move ahead with
slightly complex UI features and widgets.
This commit uses the new markup type annotation to add type hints
and annotations to important UI methods, such as `soup2markup`,
`transform_content`, and annotates other urwid.Text markup
variables.
This commit updates and simplifies the general PopUpViewContent
type annotation, and annotates other urwid text markups as usual.
@zulipbot zulipbot added the size: L [Automatic label added by zulipbot] label Jul 27, 2021
@zulipbot
Copy link
Member

Hello @zulip/server-refactoring members, this pull request was labeled with the "area: refactoring" label, so you may want to check it out!

Copy link
Member

@zee-bit zee-bit left a comment

Choose a reason for hiding this comment

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

@Ezio-Sarthak This looks great. 👍

I had a couple of doubts related to the new types since they got really complex in a few places. This may not need updating depending on the legitimacy of my doubts below, but you'll need to rebase to get around with conflicts in any case. :)

@@ -1079,11 +1080,13 @@ def footlinks_view(
def soup2markup(
cls, soup: Any, metadata: Dict[str, Any], **state: Any
) -> Tuple[
List[Any], "OrderedDict[str, Tuple[str, int, bool]]", List[Tuple[str, str]]
List[urwidTextMarkup],
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to wrap urwidTextMarkup inside a List?
urwidTextMarkup already contains an outer layer of Sequence type which should cover List?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm skeptical about this too. I think Sequence might only be applicable as a type if the contents in the sequence are not changing? (I think I discussed this on stream too?)

@@ -944,7 +944,7 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
return super().keypress(size, key)


PopUpViewTableContent = Sequence[Tuple[str, Sequence[Union[str, Tuple[str, str]]]]]
PopUpViewTableContent = Sequence[Tuple[str, urwidTextMarkup]]
Copy link
Member

Choose a reason for hiding this comment

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

Similarly here, shouldn't just urwidTextMarkup suffice? Am I misunderstanding something?

@zulipbot
Copy link
Member

Heads up @Ezio-Sarthak, we just merged some commits that conflict with the changes your made in this pull request! You can review this repository's recent commits to see where the conflicts occur. Please rebase your feature branch against the upstream/main branch and resolve your pull request's merge conflicts accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: infrastructure Project infrastructure area: refactoring has conflicts size: L [Automatic label added by zulipbot]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants