trash-cli icon indicating copy to clipboard operation
trash-cli copied to clipboard

Don't force user to install old mock library

Open andreafrancia opened this issue 1 year ago • 8 comments

          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 avatar Mar 28 '24 13:03 andreafrancia

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

andreafrancia avatar Mar 28 '24 13:03 andreafrancia

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: @.***>

a-detiste avatar Mar 28 '24 13:03 a-detiste

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

andreafrancia avatar Mar 28 '24 13:03 andreafrancia

MyPy happiness can be checked with

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

andreafrancia avatar Mar 28 '24 13:03 andreafrancia

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: @.***>

a-detiste avatar Mar 28 '24 13:03 a-detiste

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

andreafrancia avatar Mar 28 '24 13:03 andreafrancia

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

eli-schwartz avatar Jul 05 '24 02:07 eli-schwartz

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.

eli-schwartz avatar Jul 05 '24 02:07 eli-schwartz

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.

andreafrancia avatar Jul 08 '24 19:07 andreafrancia

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

Thank you so much

a-detiste avatar Jul 08 '24 19:07 a-detiste