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

[type annotation] add type hint for flowchart #2867

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

longqzh
Copy link
Contributor

@longqzh longqzh commented Nov 1, 2023

This is the second PR in the PR's sequence to add type annotation.
type hints are added in flowchartfolder.

Discussion : #2833

Other Tasks

Bump Dependency Versions

Files that need updates

Confirm the following files have been either updated or there has been a determination that no update is needed.

  • README.md
  • setup.py
  • tox.ini
  • .github/workflows/main.yml and associated requirements.txt and conda environemt.yml files
  • pyproject.toml
  • binder/requirements.txt
Pre-Release Checklist

Pre Release Checklist

  • Update version info in __init__.py
  • Update CHANGELOG primarily using contents from automated changelog generation in GitHub release page
  • Have git tag in the format of pyqtgraph-
Post-Release Checklist

Steps To Complete

  • Append .dev0 to __version__ in __init__.py
  • Announce on mail list
  • Announce on Twitter

Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

CodeQL found more than 10 potential problems in the proposed changes. Check the Files changed tab for more details.

@longqzh longqzh changed the title Add type flowchart [type annotation] add type hint for flowchart Nov 1, 2023
@longqzh
Copy link
Contributor Author

longqzh commented Nov 1, 2023

@j9ac9k, after adding the type hint, the github CodeQL start to scan the code, and reject the PR because mismatch override etc
Those potential problems are caused by code itself, and all fo them are marked by # type: ignore for mypy.

So how about disable the CodeQL until we're ready?

@j9ac9k
Copy link
Member

j9ac9k commented Nov 1, 2023

Depending on the reason codeql is failing, we can merge with it giving a red checkmark. CodeQL is intended to be a check for some basic stuff like unused imports; referencing potentially unassigned variables and so on.

That said the reason for the errors is using typing.Unpack which was added in python 3.11.

I would be good with adding typing-extensions as a dependency if using new type syntax results in inline annotations that are far easier to read/simplified.

@longqzh
Copy link
Contributor Author

longqzh commented Nov 3, 2023

@j9ac9k , Good catch! typing.Unpack cannot use in python 3.9.
But, I don't think only adding typing-extensions can solve this issue.

Firstly, codeQL can support python 3.5~3.11 codeql-overview,

Secondly, codeQL said "Overriding method process has signature mismatch with overridden method",
in the parent class Node, the process method's signature is

def process(self, **kargs: Unpack) -> dict:

but in the child class (like ImageViewNode), the signature is

def process(self, data: Optional[np.ndarray], display: bool = True) -> None:

the signature of method in the parent & child class are Different. I guess this is the real reason to fail.
I'll try to find other way to solve it, (ex, remove type hint in process method). and will share the progress :)

@j9ac9k
Copy link
Member

j9ac9k commented Nov 3, 2023

I wouldn't worry about the CodeQL issue, it being red on a PR is not a deal breaker on it merging; there are inherent shortcomings w/ that check.

Right now, there are 418 CodeQL issues in the codebase (there used to be ~1,000 but periodically I make a PR to address some of the low-hanging fruit).

@longqzh
Copy link
Contributor Author

longqzh commented Nov 3, 2023

You're right, I didn't check the detail of failed checks before.
I'll fix the Unpack issue :)

@longqzh longqzh force-pushed the add-type-flowchart branch 7 times, most recently from f465d79 to c493f4a Compare November 4, 2023 09:26
@longqzh
Copy link
Contributor Author

longqzh commented Nov 4, 2023

@j9ac9k ,
Thanks for your explanation :)
I have added type-extensions dependency in setup.py and main.yaml(for conda)
let me know if I should update any more file

@longqzh
Copy link
Contributor Author

longqzh commented Nov 18, 2023

@j9ac9k , please merge it if it's no problem :)

@j9ac9k
Copy link
Member

j9ac9k commented Feb 17, 2024

Hi @longqzh

Sorry for the silence on my end. I'm moved across the country, and am preparing for an international move in a few months so my time on this library came to a standstill for a while.

Given the NEP-29 timeline we will be dropping Python 3.9 support is just a few months. This will take away the need for using the typing_extensions module. I'm going to hold off on merging this PR until we drop Python 3.9 support. Feel free to remove the typing_extensions module. I understand if enough time has passed and you've moved on with your own projects, I would be good with taking over this PR too 👍🏻

@rwarren rwarren mentioned this pull request May 5, 2024
self.items = {}

def disconnected(self, localTerm, remoteTerm):
self.plot: Optional[PlotWidget] = None # currently selected plot
Copy link

Choose a reason for hiding this comment

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

Instance properties should be typed at the class level, not in the __init__ function (see here)... like this:

class PlotWidgetNode(Node):
    items: dict[int, QGraphicsItem | PlotDataItem
    plot: PlotWidget | PlotItem | None  # personal preference, but I only use `Optional` for function args
    plots: dict[str, PlotWidget | PlotItem]  
    ui: ComboBox | None
    
    def __init__(self, name: str) -> None:
        Node.__init__(self, name, terminals={'In': {'io': 'in', 'multi': True}})
        self.plot = None  # <-- no need for typing here! Type is defined at class level.

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.

None yet

3 participants