def test_run_time_imports_do_not_add_edges_to_graph(tmp_path_factory): files = { 'a.py': 'x = 1', 'b.py': (''' def f(): import a '''), } with _test_package(tmp_path_factory, files) as package: import b b.f() assert not _dependency_graph.has_edge('b', 'a')
def main(): print(f(42))
def main(): for k in range(10): print f(g(k)) print A().h(8)
def main(): print(f(-1))
def test(x): if x > 0: out = f() else: out = g() out.startswith('foo') # pass
import b c = b.f(2, 3) print(c)
import b from b import pi #pi = 2 def g(): global pi pi = 1 return pi g() print(pi) ###defect 1: #b.f() #print(pi) #prints out 3.14 while we suppose 4.14 ###solution: ##the only way is to use only ***b.pi*** instead of ***pi*** ##to to modify variables on other modules from another modules. b.f() pi = pi + 10 #this has no effect on b.pi #b.pi = 20 we can modify b.pi variable from main module too #b.f() # but it is better to update b.pi variable from b module by b functions instead of main module directly print(b.pi) ###defect 2: ##can not update global variable ***b.pi*** with a function. #def h(): # global b.pi # b.pi = 1 # return pi
from b import f print f("http://example.com/")
def g(): return f()
x = 11 # x глобальна только для этого файла import b # получаем доступ к именам в модуле b b.f() # изменяет переменную b.x, но не х этого файла print(x, b.x) # 11 99
def f_usage(): return f(14)
def f(): b.init() c.init() b.f() c.f() return
import b import c import c.d import c as x import c.d as y import b, c as z, c.d as w b.func() b.C() from b import func from b import func as f from b import func as f, C from b import * from c import d from c.d import v func() f() C() d # from . import b as b_alias # from . import * from .b import func as g g() # b_alias.func()
#! /usr/bin/env python3 import b if __name__ == "__main__": b.f()
def main(): print(b.f(42))