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

Typing of dseq #254

Merged
merged 1 commit into from
Sep 6, 2024
Merged

Typing of dseq #254

merged 1 commit into from
Sep 6, 2024

Conversation

manulera
Copy link
Collaborator

@manulera manulera commented Aug 12, 2024

Hi @JeffXiePL, this is an example of what you could do for including typing for a module. I have also included some extra small changes beyond indicating the types of arguments and function returns, but you don't really have to do that unless you spot something that you think needs changing.

Have a look at the files changed of this PR to see my changes.

Note the usage of TypeVar. This is useful when you want to use the same class method for a class and subclass, and the method returns that same class or subclass as output. Below is a silly minimal example that you can test in vscode:

from typing import TypeVar

T = TypeVar("T")

class myParentClass():
    def __init__(self, name: str):
        self.name = name

    def with_name_suffix(self: T, other_name: str) -> T:
        return self.__class__(other_name)

class myChildClass(myParentClass):
    def __init__(self, name: str):
        super().__init__(name)

parent = myParentClass("parent")
child = myChildClass("child")

parent2 = parent.with_name_suffix("parent2")
child2 = child.with_name_suffix("child2")

If you hold cmd and hover over parent2 and child2, you will see that the type displayed is the correct one. This is also the case if you omit the typing entirely, because vscode can infer it for this code, but it's not always the case depending on which functions are used in the body of the method, so we can be explicit and indicate it.

@manulera manulera changed the base branch from master to dev_bjorn August 12, 2024 15:31
@manulera
Copy link
Collaborator Author

@BjornFJohansson this is mostly typing for #176, but also a few refactors of dseq for better clarity or practice (e.g. checking the length of arrays instead of using try / raise).

Copy link

codecov bot commented Aug 12, 2024

Codecov Report

Attention: Patch coverage is 95.18072% with 4 lines in your changes missing coverage. Please review.

Project coverage is 93.57%. Comparing base (f156549) to head (787d00c).
Report is 1 commits behind head on dev_bjorn.

Files with missing lines Patch % Lines
src/pydna/dseq.py 94.36% 2 Missing and 2 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##           dev_bjorn     #254      +/-   ##
=============================================
- Coverage      93.67%   93.57%   -0.10%     
=============================================
  Files             40       40              
  Lines           3906     3909       +3     
  Branches         582      585       +3     
=============================================
- Hits            3659     3658       -1     
- Misses           197      199       +2     
- Partials          50       52       +2     
Files with missing lines Coverage Δ
src/pydna/common_sub_strings.py 100.00% <100.00%> (ø)
src/pydna/utils.py 93.11% <100.00%> (-0.03%) ⬇️
src/pydna/dseq.py 96.17% <94.36%> (-0.84%) ⬇️

@BjornFJohansson BjornFJohansson merged commit c590850 into dev_bjorn Sep 6, 2024
37 of 39 checks passed
@manulera manulera deleted the first_for_issue176 branch October 8, 2024 11:01
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