Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
problem in using mypy
#11
(Sep-04-2023, 02:53 PM)akbarza Wrote: hi snppsat
i replied to you, but my net disconnected and my reply was killed.
good news: i did as you said step by step and I reached to:

Output:
(new_env) c:\code\new_env>mypy --version mypy 1.5.1 (compiled: yes)
also i copied example1 in C:\code\new_env and then :

C:\WINDOWS\system32>cd C:\code\new_env

Output:
C:\code\new_env>mypy example1.py example1.py:5: ←[1m←[91merror:←[0m Argument 1 to ←[0m←[1m"slice"←[0m has incompatible type ←[0m←[1m"list[int]"←[0m; expe cted ←[0m←[1m"str"←[0m ←[0m←[93m[arg-type]←[0m ←[1m←[91mFound 1 error in 1 file (checked 1 source file)←[0m C:\code\new_env>
thanks

hi
what i did in cmd( :
c:\ pip install mypy --upgrade --no-cache-dir --force-reinstall
After running the above: I closed and opened cmd and :

Error:
C:\WINDOWS\system32>cd /d D:\14020412_enteghal\akb_python\akb_py_projects D:\14020412_enteghal\akb_python\akb_py_projects>mypy example1.py D:\14020412_enteghal\akb_python\akb_py_projects\__init__.py: error: INTERNAL ERROR -- Please try using mypy master on Gi tHub: https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build If this issue continues with mypy master, please report a bug at https://github.com/python/mypy/issues version: 1.5.1 D:\14020412_enteghal\akb_python\akb_py_projects\__init__.py: : note: please use --show-traceback to print a traceback wh en reporting a bug D:\14020412_enteghal\akb_python\akb_py_projects>
I have shame for more questions, but what's the problem? how can correct it?
Reply
#12
When it work in virtual enviroment,then there is problem with your OS Python.
As mention mypy example1.py --show-traceback to see more of the error.
Eaiset just remove Python and reinstall,also the long default path c:\users\akbar\appdata\local\programs\python\python311
Can chooise someting simpler,i just use C\python311,look at installation under Windows
Quote:also i copied example1 in C:\code\new_env and then :

C:\WINDOWS\system32>cd C:\code\new_env
No no,you don't copy out from virtual environment to try to fix stuff outside of it.
akbarza likes this post
Reply
#13
hi snippsat
I uninstalled Python and installed it again and it works. but i have some questions.
my question:
First:
in your last reply, you had written this term:
mypy example1.py --show-traceback 
.
for this --show-traceback, how can i know that a command( e.g. mypy) has such tails like this?(I do not know what is called this, so I named it tail.) and what tails does it have? what thing do i search for it in google?

Second: I copied example1.py file on my desktop and in cmd after changing path
and writing
 mypy example1.py
, i have:

C:\WINDOWS\system32>cd/d C:\Users\akbar\Desktop\1

C:\Users\akbar\Desktop\1>mypy example1.py
example1.py:5: ←[1m←[91merror:←[0m Argument 1 to ←[0m←[1m"slice"←[0m has incompatible type ←[0m←[1m"list[int]"←[0m; expe
cted ←[0m←[1m"str"←[0m ←[0m←[93m[arg-type]←[0m
←[1m←[91mFound 1 error in 1 file (checked 1 source file)←[0m


I think mypy acted correctly, but I do not understand these expressions such as 0m, 1m, 91m and ... .
can explain to me or introduce to me a reference?
thanks
Reply
#14
Quote: how can i know that a command( e.g. mypy) has such tails like this?
Ask for help. Almost all command line tools provide help.
Output:
(env) > mypy usage: mypy [-h] [-v] [-V] [more options; see below] [-m MODULE] [-p PACKAGE] [-c PROGRAM_TEXT] [files ...] mypy: error: Missing target module, package, files, or command. (env) > mypy -h usage: mypy [-h] [-v] [-V] [more options; see below] [-m MODULE] [-p PACKAGE] [-c PROGRAM_TEXT] [files ...] ... much more to follow
akbarza likes this post
Reply
#15
(Sep-05-2023, 11:56 AM)akbarza Wrote: I think mypy acted correctly, but I do not understand these expressions such as 0m, 1m, 91m and ... .
can explain to me or introduce to me a reference?
That because cmd is bad command shell and can not display color.
I would advice to use cmder ,here how same code look in cmder.
[Image: z0WUeV.png]
Also using Rich-CLI then also get color when view files
akbarza likes this post
Reply
#16
hi
First: I have another problem related to mypy but I did not know that I must create a new thread or continue to this thread. so I am writing here.
As you read this thread from the first, I recently reinstalled Python and it has been installed in C:\python_3_11_5 .
but I save my Python files in D:\14020412_enteghal\akb_python\akb_py_projects\

in the code( reference to site containing this code is in first line and i saved this code in my pc as fib.py):
# from https://www.geeksforgeeks.org/function-annotations-python/

# Python program to print Fibonacci series
def fibo(n:'int', output:'list'=[])-> 'list':
    if n == 0:
        return output
    else:
        if len(output)< 2:
            output.append(1)
            fibo(n-1, output)
        else:
            last = output[-1]
            second_last = output[-2]
            output.append(last + second_last)
            fibo(n-1, output)
        return output
print(fibo(5))
When I run it in idle shell 3.11.5, it is okay and print in output :
Output:
[1, 1, 2, 3, 5]
Also when I run it from cmd, I take the above
but when i write mypy fib.py in cmd , an error message is shown:

Error:
D:\14020412_enteghal\akb_python\akb_py_projects>mypy fib.py __init__.py: error: source code string cannot contain null bytes [syntax] Found 1 error in 1 file (errors prevented further checking) D:\14020412_enteghal\akb_python\akb_py_projects>
I searched the net but I did not find a solution. (I also found and read https://python-forum.io/thread-40466.html, but it is not related to my problem).
What is the problem? and why it is related to __init__.py?
Thanks for any guidance.
Reply
#17
hi
there was the file __iinit__.py in D:\14020412_enteghal\akb_python\akb_py_projects\ .
when i deleted it, the erro was solved :
after deleting __init__.py in above directory:

Error:
D:\14020412_enteghal\akb_python\akb_py_projects>mypy fib.py Success: no issues found in 1 source file D:\14020412_enteghal\akb_python\akb_py_projects>
but what relation eas between mypy and __init__.py?
Reply
#18
(Sep-06-2023, 12:56 PM)akbarza Wrote: but what relation eas between mypy and __init__.py?
It's more about how Python search for for files,it first search for built-in module or eg your packages/modules.
If have __init__.py in a folder(Python think it's a module) if will find that first,before it find fib.py.
(Sep-06-2023, 12:56 PM)akbarza Wrote: When I run it in idle shell 3.11.5, it is okay and print in output :
Output:
[1, 1, 2, 3, 5]
Quote:It's important to note that type annotations in Python are purely optional,
and do not affect the runtime behavior of your code.
They are simply a way to provide additional information tools that can help improve the quality and maintainability of your code
akbarza likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  mypy, type aliases and type variables tomciodev 1 714 Oct-18-2023, 10:08 AM
Last Post: Larz60+
Question mypy unable to analyse types of tuple elements in a list comprehension tomciodev 1 484 Oct-17-2023, 09:46 AM
Last Post: tomciodev
  Mypy typing error WannaBePythonDev 2 1,939 Sep-05-2021, 10:18 AM
Last Post: WannaBePythonDev

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020