#๐Ÿ”’ testing for broken imports

47 messages ยท Page 1 of 1 (latest)

signal pike
#

is there a reasonable python checker that checks imports - a broken import passes
py_compile, pyflakes, and pylance checks ...
this code has no warnings in visual studio, but crashes at runtime:

async def foo():
    from os import thing_that_doesnt_exist as dothing
    result = dothing()
    return result 
foo()

how could i check this code for correctness?

arctic abyssBOT
#

@signal pike

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

surreal mural
#

!e

async def f():
from os import abc as d

arctic abyssBOT
surreal mural
#

what

#

ohhh

signal pike
#

yeah, this is the issue i'm dealing with ...

surreal mural
#

it's because the function isn't run

#

move the imports to the top of the file

signal pike
#

i want a compile time / code lint check, rather than exploding at runtime ...

surreal mural
#

ruff makes you do this by default fyi

surreal mural
signal pike
#

!e

from os import abc as d

arctic abyssBOT
surreal mural
#

what

#

!e from sys import abracadabra as abc

arctic abyssBOT
# surreal mural !e from sys import abracadabra as abc

:x: Your 3.12 eval job has completed with return code 1.

001 | Traceback (most recent call last):
002 |   File "/home/main.py", line 1, in <module>
003 |     from sys import abracadabra as abc
004 | ImportError: cannot import name 'abracadabra' from 'sys' (unknown location)
surreal mural
#

weird how that doesnt do anything for os

#

!e from os import abracadabra

arctic abyssBOT
# surreal mural !e from os import abracadabra

:x: Your 3.12 eval job has completed with return code 1.

001 | Traceback (most recent call last):
002 |   File "/home/main.py", line 1, in <module>
003 |     from os import abracadabra
004 | ImportError: cannot import name 'abracadabra' from 'os' (/snekbin/python/3.12/lib/python3.12/os.py)
surreal mural
#

no it still does

#

!e from os import abc

arctic abyssBOT
surreal mural
#

!e from os import abc

print(abc)

arctic abyssBOT
surreal mural
#

ohhh

#

thats this

#

!d abc

arctic abyssBOT
#
abc

Source code: Lib/abc.py

This module provides the infrastructure for defining abstract base classes (ABCs) in Python, as outlined in PEP 3119; see the PEP for why this was added to Python. (See also PEP 3141 and the numbers module regarding a type hierarchy for numbers based on ABCs.)

The collections module has some concrete classes that derive from ABCs; these can, of course, be further derived. In addition, the collections.abc submodule has some ABCs that can be used to test whether a class or instance provides a particular interface, for example, if it is hashable or if it is a mapping...

signal pike
#

!e from os import thing_that_doesnt_exist as theThing

print(theThing)

arctic abyssBOT
surreal mural
#

!e

def f():
from os import thing_that_doesnt_exist

f()

signal pike
#

fails at runtime, but how do you lint that?

arctic abyssBOT
# surreal mural !e def f(): from os import thing_that_doesnt_exist f()

:x: Your 3.12 eval job has completed with return code 1.

001 | Traceback (most recent call last):
002 |   File "/home/main.py", line 4, in <module>
003 |     f()
004 |   File "/home/main.py", line 2, in f
005 |     from os import thing_that_doesnt_exist
006 | ImportError: cannot import name 'thing_that_doesnt_exist' from 'os' (/snekbin/python/3.12/lib/python3.12/os.py)
surreal mural
#

but this is quite strange

signal pike
#

no warnings in vscode

surreal mural
#

like i said earlier, does it lint at the top?

#

well clearly not

surreal mural
#

what's your pylance set to?

#

should be like off, basic, normal and strict

signal pike
#

not sure - how do i check in vscode?

#

aha - yes, that needed to be turned up ๐Ÿ™‚

arctic abyssBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.