Skip to content

Instantly share code, notes, and snippets.

@sb2nov
Created June 6, 2017 00:06
Show Gist options
  • Save sb2nov/52b5091fcc7135bcd02948088d876d5b to your computer and use it in GitHub Desktop.
Save sb2nov/52b5091fcc7135bcd02948088d876d5b to your computer and use it in GitHub Desktop.
Test python import
class A(object):
def __init__():
print 'A'
from a import A
class B(A):
def __init__():
print 'B'
from a import A
class C(A):
def __init__():
print 'C'
from a import A
print A.__subclasses__()
# []
from b import B
print A.__subclasses__()
# [<class 'b.B'>]
from c import C
print A.__subclasses__()
# [<class 'b.B'>, <class 'c.C'>]
@robertwb
Copy link

robertwb commented Jun 6, 2017

If you just write "import b" instead of "from b import B" this will work as well. Likewise, if you import (say) c from b.py, there's no need to import it from test.py.

@sb2nov
Copy link
Author

sb2nov commented Jun 6, 2017

Thanks @robertwb, one follow up questions for the beam plugin case

myfs.py installed via pip somewhere

class MyFS(FileSystem):
   def __init__():
       print 'This is my fs implementation'

my_pipeline.py

p = Pipeline() | TextIO("myfs://path/to/file")
p.run()

python -m my_pipeline --runner DataflowRunner how does this find the myfs implementation when it is not imported anywhere. Is the hope that the user is going to import this in the pipeline ?

@robertwb
Copy link

robertwb commented Jun 6, 2017

The user must cause this to be imported to indicate that they want to use it. (Perhaps directly, perhaps some runners will import certain filesystems themselves.)

@sb2nov
Copy link
Author

sb2nov commented Jun 6, 2017

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment