andreafrancia / trash-cli

Command line interface to the freedesktop.org trashcan.
GNU General Public License v2.0
3.52k stars 177 forks source link

Don't force user to install old mock library #339

Open andreafrancia opened 3 months ago

andreafrancia commented 3 months ago
          No problem.

Would you accept to hybridize mock usage ?

Like this:

try: from unittest import mock except ImportError: import mock

We are slowly trying to remove mock,nose,unittest2,future etc... from Debian; so what is done is done :-)

Le jeu. 28 mars 2024 à 12:27, Andrea Francia @.***> a écrit :

Thank you for your contribution but I'm still using the old mock library to keep trash-cli compatible with python 2.7

— Reply to this email directly, view it on GitHub https://github.com/andreafrancia/trash-cli/pull/331#issuecomment-2024958427, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB47WUGAGZUZYU7ZBKTPG6TY2PWA7AVCNFSM6AAAAABCDJAI5WVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMRUHE2TQNBSG4 . You are receiving this because you authored the thread.Message ID: @.***>

Originally posted by @a-detiste in https://github.com/andreafrancia/trash-cli/issues/331#issuecomment-2025114990

andreafrancia commented 3 months ago

Yes, but this code should be put in single place. We already have code like this:

from trashcli.compat import Protocol

If you want can make it works also for Mock and call, something like

from trashcli.compat import Mock
from trashcli.compat import call

Thank you

a-detiste commented 3 months ago

What's the purpose of the wrapping ?

def protocol():
     (wrapped code)

Protocol = protocol()

del protocol

I think this should do the same: (I ve seen this construct in many other projects)

__all__ = ['Protocol']
try:
    from typing import Protocol
except ImportError as e:
    from typing_extensions import Protocol

Le jeu. 28 mars 2024 à 14:30, Andrea Francia @.***> a écrit :

Yes, but this code should be put in single place. We already have code like this:

from trashcli.compat import Protocol

If you want can make it works also for Mock and call, something like

from trashcli.compat import Mockfrom trashcli.compat import call

Thank you

— Reply to this email directly, view it on GitHub https://github.com/andreafrancia/trash-cli/issues/339#issuecomment-2025192221, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB47WUE3E3BGYXNSZE6QNTTY2QENBAVCNFSM6AAAAABFMZKHV2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMRVGE4TEMRSGE . You are receiving this because you were mentioned.Message ID: @.***>

andreafrancia commented 3 months ago

I don't remember, I think to make MyPy happy.

andreafrancia commented 3 months ago

MyPy happiness can be checked with

$ pip install -r requirements.txt -r requirements-dev.txt 
$ scripts/check-types
a-detiste commented 3 months ago

ok I'll check ...: it's unrelated but if you know a tool to automatically rewrite Python2-style annotations in Python3 style that would be welcome (I have to translate a project with +>1000 annotated functions)

Le jeu. 28 mars 2024 à 14:45, Andrea Francia @.***> a écrit :

MyPy happiness can be checked with

$ pip install -r requirements.txt -r requirements-dev.txt $ scripts/check-types

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

andreafrancia commented 3 months ago

I don't know any tool like that, I'm sorry :(

eli-schwartz commented 4 days ago

I think the tool you want is probably https://github.com/ilevkivskyi/com2ann?

eli-schwartz commented 4 days ago

Yes, but this code should be put in single place. We already have code like this:

from trashcli.compat import Protocol

I would recommend not doing it like this, because it's problematic and prevents automatic rewriting. And the try/except is very hard for type checkers and linters to understand. Instead it is recommended to do an if/else on sys.version_info.

andreafrancia commented 1 day ago

Yes, but this code should be put in single place. We already have code like this:

from trashcli.compat import Protocol

I would recommend not doing it like this, because it's problematic and prevents automatic rewriting. And the try/except is very hard for type checkers and linters to understand. Instead it is recommended to do an if/else on sys.version_info.

Please provide a different solution if you have one.

a-detiste commented 1 day ago

I think the tool you want is probably https://github.com/ilevkivskyi/com2ann?

Thank you so much