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

misc. move typing improvements, WIP #195

Merged
merged 7 commits into from
Nov 23, 2023
Merged

misc. move typing improvements, WIP #195

merged 7 commits into from
Nov 23, 2023

Conversation

a-detiste
Copy link
Contributor

Hi,

I'm back working on this. I don't mind doing the + from __future__ import - Union & Optional by hand if pyupgrade can't.

#191

@codecov-commenter
Copy link

codecov-commenter commented Nov 23, 2023

Codecov Report

Attention: 13 lines in your changes are missing coverage. Please review.

Comparison is base (d832043) 81.00% compared to head (6f78532) 81.35%.

Files Patch % Lines
duecredit/cmdline/cmd_summary.py 57.14% 2 Missing and 1 partial ⚠️
duecredit/cmdline/cmd_test.py 66.66% 1 Missing and 1 partial ⚠️
duecredit/collector.py 86.66% 1 Missing and 1 partial ⚠️
duecredit/__main__.py 50.00% 1 Missing ⚠️
duecredit/dueswitch.py 83.33% 1 Missing ⚠️
duecredit/entries.py 80.00% 1 Missing ⚠️
duecredit/io.py 80.00% 1 Missing ⚠️
duecredit/tests/test__main__.py 80.00% 1 Missing ⚠️
duecredit/utils.py 75.00% 1 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #195      +/-   ##
==========================================
+ Coverage   81.00%   81.35%   +0.34%     
==========================================
  Files          47       47              
  Lines        2517     2548      +31     
  Branches      365      362       -3     
==========================================
+ Hits         2039     2073      +34     
+ Misses        383      382       -1     
+ Partials       95       93       -2     
Flag Coverage Δ
unittests 81.24% <91.39%> (+0.38%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@a-detiste
Copy link
Contributor Author

@jwodder @yarikoptic

from functools import wraps
from typing import Any, Dict, List, Optional, Tuple, Union
from typing import Any, Dict, List, Optional, Tuple, Union, TYPE_CHECKING
Copy link
Contributor

Choose a reason for hiding this comment

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

You're still using Dict, List, Tuple, etc. instead of dict, list, tuple, etc., which you can use now thanks to from __future__ import annotations. Please switch. (Pyupgrade should convert automatically now that the files contain from __future__ import annotations.)

Copy link
Contributor Author

@a-detiste a-detiste Nov 23, 2023

Choose a reason for hiding this comment

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

I first modified only 1 file this way to let CI run.

@@ -40,8 +39,8 @@ def test_main_version(monkeypatch: 'MonkeyPatch') -> None:


def test_main_run_a_script(
tmpdir: 'TempdirFactory',
monkeypatch: 'MonkeyPatch'
tmpdir: TempPathFactory,
Copy link
Contributor

Choose a reason for hiding this comment

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

tmpdir is a py.path.local.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks

@@ -20,10 +22,13 @@

__docformat__ = 'restructuredtext'

if TYPE_CHECKING:
import argparse
Copy link
Contributor

Choose a reason for hiding this comment

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

There's no downside to importing argparse. Why gate it behind if TYPE_CHECKING?



if TYPE_CHECKING:
import argparse
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, no reason for if TYPE_CHECKING.

self._rawentry = rawentry
self._key = key or rawentry.lower()

def __eq__(self, other: object) -> bool:
if not isinstance(other, DueCreditEntry):
raise NotImplemented
raise NotImplementedError
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
raise NotImplementedError
return NotImplemented

@a-detiste a-detiste merged commit 2327f9f into master Nov 23, 2023
15 checks passed
@a-detiste a-detiste deleted the PR_191_review branch November 23, 2023 16:39
self._rawentry = rawentry
self._key = key or rawentry.lower()

def __eq__(self, other: object) -> bool:
if not isinstance(other, DueCreditEntry):
raise NotImplemented
return NotImplemented
Copy link
Member

Choose a reason for hiding this comment

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

I don't think it makes sense to return here

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

ah -- cool, learned something new again, should have checked.

FWIW - here is a trial on a simple case
❯ python -m trace --trace notimpl.py
 --- modulename: notimpl, funcname: <module>
notimpl.py(1): class A:
 --- modulename: notimpl, funcname: A
notimpl.py(1): class A:
notimpl.py(2):     def __eq__(self, other):
notimpl.py(8): print(A() == A())
 --- modulename: notimpl, funcname: __eq__
notimpl.py(3):         if isinstance(other, A):
notimpl.py(4):             return True
True
notimpl.py(9): print(A() == 1)
 --- modulename: notimpl, funcname: __eq__
notimpl.py(3):         if isinstance(other, A):
notimpl.py(6):             return NotImplemented
False
notimpl.py(10): print(A() != 1)
 --- modulename: notimpl, funcname: __eq__
notimpl.py(3):         if isinstance(other, A):
notimpl.py(6):             return NotImplemented
True
❯ cat notimpl.py
class A:
    def __eq__(self, other):
        if isinstance(other, A):
            return True
        else:
            return NotImplemented

print(A() == A())
print(A() == 1)
print(A() != 1)

I will revert that f470c3e I merged in rush, directly in master

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

4 participants